Skip to content

Commit

Permalink
hmac: Fix passing in a string for digestmod argument.
Browse files Browse the repository at this point in the history
The built-in `hashlib` module does not have a `.new` method (although the
Python version in this repository does).
  • Loading branch information
Pharkie authored and dpgeorge committed Feb 7, 2024
1 parent 35d41db commit ddb1a27
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion python-stdlib/hmac/hmac.py
Expand Up @@ -17,7 +17,7 @@ def __init__(self, key, msg=None, digestmod=None):
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
Expand Down
2 changes: 1 addition & 1 deletion python-stdlib/hmac/manifest.py
@@ -1,3 +1,3 @@
metadata(version="3.4.3")
metadata(version="3.4.4")

module("hmac.py")
2 changes: 1 addition & 1 deletion python-stdlib/hmac/test_hmac.py
Expand Up @@ -8,7 +8,7 @@

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)
Expand Down

1 comment on commit ddb1a27

@Pharkie
Copy link
Contributor Author

@Pharkie Pharkie commented on ddb1a27 Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great! Thanks for impriving - I wasn't quite sure how to contribute and update the test etc

Please sign in to comment.