diff --git a/python-stdlib/hashlib/hashlib/__init__.py b/python-stdlib/hashlib/hashlib/__init__.py index d7afbf819..86fd8d42f 100644 --- a/python-stdlib/hashlib/hashlib/__init__.py +++ b/python-stdlib/hashlib/hashlib/__init__.py @@ -6,11 +6,18 @@ def init(): for i in ("sha1", "sha224", "sha256", "sha384", "sha512"): - c = getattr(uhashlib, i, None) - if not c: + # first try to import the python-stdlib hash so that we are compatible + # with e.g. hmac (uhashlib lacks {digest,block}_size, copy()) + try: c = __import__("_" + i, None, None, (), 1) c = getattr(c, i) - globals()[i] = c + except ImportError: + c = None + # fallback to uhashlib (e.g. sha1) + if not c: + c = getattr(uhashlib, i, None) + if c: + globals()[i] = c init() diff --git a/python-stdlib/hashlib/test_hashlib.py b/python-stdlib/hashlib/test_hashlib.py index 6cb687399..812248ae2 100644 --- a/python-stdlib/hashlib/test_hashlib.py +++ b/python-stdlib/hashlib/test_hashlib.py @@ -9,6 +9,11 @@ import hashlib patterns = [ + ( + "sha1", + b"1234", + b"q\x10\xed\xa4\xd0\x9e\x06*\xa5\xe4\xa3\x90\xb0\xa5r\xac\r,\x02\x20", + ), ( "sha224", b"1234",