import hmac
import hashlib


def is_valid_secret(secret_server, secret, payload):
    """Validate a GitHub webhook secret token/payload"""

    is_valid = False

    if secret is None:
        return False

    sha_name, signature = secret.split('=')

    if sha_name != 'sha1':
        return False

    mac = hmac.new(secret_server, msg=payload, digestmod=hashlib.sha1)

    try:
        is_valid = hmac.compare_digest(str(mac.hexdigest()), signature)
    except AttributeError:
        is_valid = str(mac.hexdigest()) == str(signature)

    return is_valid