FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-141907: Better handle support for SHA3 for test_hashlib (GH-141908) by miss-islington · Pull Request #141918 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
27 changes: 18 additions & 9 deletions Lib/test/test_hashlib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@
openssl_hashlib = import_fresh_module('hashlib', fresh=['_hashlib'])

try:
from _hashlib import HASH, HASHXOF, openssl_md_meth_names, get_fips_mode
import _hashlib
except ImportError:
HASH = None
HASHXOF = None
openssl_md_meth_names = frozenset()

_hashlib = None
# The extension module may exist but only define some of these. gh-141907
HASH = getattr(_hashlib, 'HASH', None)
HASHXOF = getattr(_hashlib, 'HASHXOF', None)
openssl_md_meth_names = getattr(_hashlib, 'openssl_md_meth_names', frozenset())
get_fips_mode = getattr(_hashlib, 'get_fips_mode', None)
if not get_fips_mode:
def get_fips_mode():
return 0

Expand Down Expand Up @@ -566,9 +569,14 @@ def check_sha3(self, name, capacity, rate, suffix):
constructors = self.constructors_to_test[name]
for hash_object_constructor in constructors:
m = hash_object_constructor()
if HASH is not None and isinstance(m, HASH):
# _hashopenssl's variant does not have extra SHA3 attributes
continue
if name.startswith('shake_'):
if HASHXOF is not None and isinstance(m, HASHXOF):
# _hashopenssl's variant does not have extra SHA3 attributes
continue
else:
if HASH is not None and isinstance(m, HASH):
# _hashopenssl's variant does not have extra SHA3 attributes
continue
self.assertEqual(capacity + rate, 1600)
self.assertEqual(m._capacity_bits, capacity)
self.assertEqual(m._rate_bits, rate)
Expand Down Expand Up @@ -1070,7 +1078,8 @@ def test_disallow_instantiation(self):
def test_hash_disallow_instantiation(self):
# internal types like _hashlib.HASH are not constructable
support.check_disallow_instantiation(self, HASH)
support.check_disallow_instantiation(self, HASHXOF)
if HASHXOF is not None:
support.check_disallow_instantiation(self, HASHXOF)

def test_readonly_types(self):
for algorithm, constructors in self.constructors_to_test.items():
Expand Down
Loading

Back | FazBrowse Home | New Git URL