Skip to content

Commit ddb1a27

Browse files
Pharkiedpgeorge
authored andcommitted
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).
1 parent 35d41db commit ddb1a27

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

python-stdlib/hmac/hmac.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self, key, msg=None, digestmod=None):
1717
make_hash = digestmod # A
1818
elif isinstance(digestmod, str):
1919
# A hash name suitable for hashlib.new().
20-
make_hash = lambda d=b"": hashlib.new(digestmod, d) # B
20+
make_hash = lambda d=b"": getattr(hashlib, digestmod)(d)
2121
else:
2222
# A module supporting PEP 247.
2323
make_hash = digestmod.new # C

python-stdlib/hmac/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metadata(version="3.4.3")
1+
metadata(version="3.4.4")
22

33
module("hmac.py")

python-stdlib/hmac/test_hmac.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
msg = b"zlutoucky kun upel dabelske ody"
1010

11-
dig = hmac.new(b"1234567890", msg=msg, digestmod=hashlib.sha256).hexdigest()
11+
dig = hmac.new(b"1234567890", msg=msg, digestmod="sha256").hexdigest()
1212

1313
print("c735e751e36b08fb01e25794bdb15e7289b82aecdb652c8f4f72f307b39dad39")
1414
print(dig)

0 commit comments

Comments
 (0)