Closed EdOverflow closed 7 years ago
@EdOverflow, because this function was introduced in Python 2.7.7, could you add a little bit of fallback logic? For example:
try:
from hmac import compare_digest
except ImportError:
def compare_digest(a, b):
return a == b
Good idea @jparise! The only thing I want to do a bit differently is make sure that the fallback is also a constant time comparison:
try:
from hmac import compare_digest
except ImportError:
def compare_digest(a, b):
if len(a) != len(b):
return False
result = 0
for x, y in zip(a, b):
result |= ord(x) ^ ord(y)
return result == 0
Thanks @EdOverflow!
Since all checks have passed, can we merge this PR?