Onionr/onionr/onionrcrypto/cryptoutils/safecompare.py
2019-07-19 19:01:16 -05:00

12 lines
276 B
Python

import hmac
def safe_compare(one, two):
# Do encode here to avoid spawning core
try:
one = one.encode()
except AttributeError:
pass
try:
two = two.encode()
except AttributeError:
pass
return hmac.compare_digest(one, two)