Skip to content

Commit f4af921

Browse files
author
brentru
committed
only import submodules if not hashlib
1 parent c296ce4 commit f4af921

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

adafruit_hashlib/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@
4242
try:
4343
import hashlib
4444
except ImportError:
45-
hashlib = None
45+
from adafruit_hashlib._sha256 import sha224, sha256
46+
from adafruit_hashlib._sha512 import sha384, sha512
4647

4748
__version__ = "0.0.0-auto.0"
4849
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_hashlib.git"
4950

5051
# FIPS secure hash algorithms supported by this library
5152
ALGOS_AVAIL = ["sha1", "MD5", "sha224", "sha256", "sha384", "sha512"]
5253

53-
from adafruit_hashlib._sha256 import sha224, sha256
54-
from adafruit_hashlib._sha512 import sha384, sha512
55-
5654
def new(algo, data=b""):
5755
"""Creates a new hashlib object.
5856
:param str algo: Name of the desired algorithm.

examples/hashlib_simpletest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
m.update(byte_string)
1212
# Obtain the digest, digest size, and block size
1313
print(
14-
"Msg Digest: {}\nMsg Digest Size: {}\nMsg Block Size: {}".format(
15-
m.hexdigest(), m.digest_size, m.block_size))
14+
"Msg Digest: {}\nMsg Digest Size: {}\nMsg Block Size: {}".format(
15+
m.hexdigest(), m.digest_size, m.block_size))
1616
# Validate the digest
1717
assert (
1818
m.hexdigest() == "744535a10879be6b18bbcdd135032891346f530a7845d580f7869f36"

0 commit comments

Comments
 (0)