import hmac


def _valid_signature(gh_signature, body, secret):
    """Returns True if GitHub signature is valid. False, otherwise."""
    def to_str(s):
        if isinstance(s, str):
            return bytes(s, encoding='utf-8')
        else:
            return s

    gh_signature = to_str(gh_signature)
    body = to_str(body)
    secret = to_str(secret)

    expected_hmac = hmac.new(secret,
                             body, digestmod="sha1")
    expected_signature = to_str('sha1=' + expected_hmac.hexdigest())
    return hmac.compare_digest(expected_signature, gh_signature)