2019-07-20 00:01:16 +00:00
|
|
|
import hmac
|
2022-08-03 05:23:22 +00:00
|
|
|
|
|
|
|
|
2019-07-20 00:01:16 +00:00
|
|
|
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
|
2022-08-03 05:23:22 +00:00
|
|
|
return hmac.compare_digest(one, two)
|
|
|
|
|