import hmac
import hashlib


def authenticate_request(shared_secret: str, body: str, signature: str) -> bool:
    """Checks if the MAC (message authentication code) sent in the request is really
    from GitHub.

    Args:
        shared_secret: A secret shared between GitHub and the bot.
        body: Body of the HTTP request.
        signature: The header containing the MAC.
    Returns:
        True iff the signature is a MAC computed with the body of the request and the
        shared secret.
    """
    if signature is None:
        return False

    sha_body = hmac.new(
        shared_secret.encode("utf8"), body.encode("utf8"), hashlib.sha1
    ).hexdigest()
    _, sha_github = signature.split("=")
    return hmac.compare_digest(sha_body, sha_github)