hmac: Fix passing in a string for digestmod argument.

The built-in `hashlib` module does not have a `.new` method (although the
Python version in this repository does).
pull/789/head
Adam Knowles 2024-01-20 11:44:02 +00:00 zatwierdzone przez Damien George
rodzic 35d41dbb0e
commit ddb1a27957
3 zmienionych plików z 3 dodań i 3 usunięć

Wyświetl plik

@ -17,7 +17,7 @@ class HMAC:
make_hash = digestmod # A
elif isinstance(digestmod, str):
# A hash name suitable for hashlib.new().
make_hash = lambda d=b"": hashlib.new(digestmod, d) # B
make_hash = lambda d=b"": getattr(hashlib, digestmod)(d)
else:
# A module supporting PEP 247.
make_hash = digestmod.new # C

Wyświetl plik

@ -1,3 +1,3 @@
metadata(version="3.4.3")
metadata(version="3.4.4")
module("hmac.py")

Wyświetl plik

@ -8,7 +8,7 @@ import hashlib
msg = b"zlutoucky kun upel dabelske ody"
dig = hmac.new(b"1234567890", msg=msg, digestmod=hashlib.sha256).hexdigest()
dig = hmac.new(b"1234567890", msg=msg, digestmod="sha256").hexdigest()
print("c735e751e36b08fb01e25794bdb15e7289b82aecdb652c8f4f72f307b39dad39")
print(dig)