From 3cc41fbcf9bad8f77e1c3e5d58af109e47dd566a Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 1 Jun 2023 17:25:02 +1000 Subject: [PATCH] hashlib: Provide all built-in hash functions. If a port had md5 enabled, then it would no longer be available. Retain the existing logic of using the built-in preferentially. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- python-stdlib/hashlib/hashlib/__init__.py | 24 +++++++++++------------ python-stdlib/hashlib/hashlib/_sha224.py | 1 - python-stdlib/hashlib/hashlib/_sha384.py | 1 - python-stdlib/hashlib/manifest.py | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 python-stdlib/hashlib/hashlib/_sha224.py delete mode 100644 python-stdlib/hashlib/hashlib/_sha384.py diff --git a/python-stdlib/hashlib/hashlib/__init__.py b/python-stdlib/hashlib/hashlib/__init__.py index d7afbf819..c5301182c 100644 --- a/python-stdlib/hashlib/hashlib/__init__.py +++ b/python-stdlib/hashlib/hashlib/__init__.py @@ -1,19 +1,19 @@ +# Use built-in functions preferentially (on most ports this is just sha256). try: - import uhashlib + from uhashlib import * except ImportError: - uhashlib = None + pass -def init(): - for i in ("sha1", "sha224", "sha256", "sha384", "sha512"): - c = getattr(uhashlib, i, None) - if not c: - c = __import__("_" + i, None, None, (), 1) - c = getattr(c, i) - globals()[i] = c - - -init() +# Add missing functions. +if "sha224" not in globals(): + from ._sha256 import sha224 +if "sha256" not in globals(): + from ._sha256 import sha256 +if "sha384" not in globals(): + from ._sha512 import sha384 +if "sha512" not in globals(): + from ._sha512 import sha512 def new(algo, data=b""): diff --git a/python-stdlib/hashlib/hashlib/_sha224.py b/python-stdlib/hashlib/hashlib/_sha224.py deleted file mode 100644 index 634343b50..000000000 --- a/python-stdlib/hashlib/hashlib/_sha224.py +++ /dev/null @@ -1 +0,0 @@ -from ._sha256 import sha224 diff --git a/python-stdlib/hashlib/hashlib/_sha384.py b/python-stdlib/hashlib/hashlib/_sha384.py deleted file mode 100644 index 20f09ff00..000000000 --- a/python-stdlib/hashlib/hashlib/_sha384.py +++ /dev/null @@ -1 +0,0 @@ -from ._sha512 import sha384 diff --git a/python-stdlib/hashlib/manifest.py b/python-stdlib/hashlib/manifest.py index 106168bab..6575d670d 100644 --- a/python-stdlib/hashlib/manifest.py +++ b/python-stdlib/hashlib/manifest.py @@ -1,3 +1,3 @@ -metadata(version="2.4.0-4") +metadata(version="2.5.0") package("hashlib")