From ddb1a279578bfff8c1b18aff3baa668620684f64 Mon Sep 17 00:00:00 2001 From: Adam Knowles <1413836+Pharkie@users.noreply.github.com> Date: Sat, 20 Jan 2024 11:44:02 +0000 Subject: [PATCH] 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). --- python-stdlib/hmac/hmac.py | 2 +- python-stdlib/hmac/manifest.py | 2 +- python-stdlib/hmac/test_hmac.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python-stdlib/hmac/hmac.py b/python-stdlib/hmac/hmac.py index 28631042f..dbbdd4718 100644 --- a/python-stdlib/hmac/hmac.py +++ b/python-stdlib/hmac/hmac.py @@ -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 diff --git a/python-stdlib/hmac/manifest.py b/python-stdlib/hmac/manifest.py index 28d78988d..ff0a62f08 100644 --- a/python-stdlib/hmac/manifest.py +++ b/python-stdlib/hmac/manifest.py @@ -1,3 +1,3 @@ -metadata(version="3.4.3") +metadata(version="3.4.4") module("hmac.py") diff --git a/python-stdlib/hmac/test_hmac.py b/python-stdlib/hmac/test_hmac.py index d155dd6a2..1cfcf4e37 100644 --- a/python-stdlib/hmac/test_hmac.py +++ b/python-stdlib/hmac/test_hmac.py @@ -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)