Kaydet (Commit) 58176dee authored tarafından Alex Gaynor's avatar Alex Gaynor

Use the stdlib's compare_digest for constant time comparisons when available

üst 9fb95dfc
......@@ -77,7 +77,11 @@ def get_random_string(length=12,
return ''.join(random.choice(allowed_chars) for i in range(length))
def constant_time_compare(val1, val2):
if hasattr(hmac, "compare_digest"):
# Prefer the stdlib implementation, when available.
constant_time_compare = hmac.compare_digest
else:
def constant_time_compare(val1, val2):
"""
Returns True if the two strings are equal, False otherwise.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment