import hmac
import hashlib


def compare_digest(a, b):
    """Intended to be a constant-time comparison."""
    if hasattr(hmac, 'compare_digest'):
        return hmac.compare_digest(a, b)
    return hashlib.sha1(a).digest() == hashlib.sha1(b).digest()