crypto: remove py2 compatibility code (#52929)

This commit is contained in:
Benjamin Dauvergne 2021-04-16 01:22:17 +02:00
parent cf9c0b2cc0
commit afc6ecd8eb
1 changed files with 6 additions and 6 deletions

View File

@ -191,10 +191,10 @@ def aes_base64url_deterministic_decrypt(key, urlencoded, salt, raise_on_error=Tr
def hmac_url(key, url):
if hasattr(key, 'isnumeric'):
key = key.encode('utf-8')
if hasattr(url, 'isnumeric'):
url = url.encode('utf-8', 'replace')
if hasattr(key, 'encode'):
key = key.encode()
if hasattr(url, 'encode'):
url = url.encode()
return (
base64.b32encode(hmac.HMAC(key=key, msg=url, digestmod=hashlib.sha256).digest())
.decode('ascii')
@ -203,6 +203,6 @@ def hmac_url(key, url):
def check_hmac_url(key, url, signature):
if hasattr(signature, 'isnumeric'):
signature = signature.encode('utf-8', 'replace')
if hasattr(signature, 'decode'):
signature = signature.decode()
return constant_time_compare(signature, hmac_url(key, url).encode('ascii'))