mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
bpo-38153: Normalize hashlib algorithm names (GH-16083)
Signed-off-by: Christian Heimes <christian@python.org>
This commit is contained in:
parent
375a3e2bdb
commit
995b5d38e7
4 changed files with 179 additions and 32 deletions
|
@ -26,6 +26,11 @@ COMPILED_WITH_PYDEBUG = hasattr(sys, 'gettotalrefcount')
|
|||
c_hashlib = import_fresh_module('hashlib', fresh=['_hashlib'])
|
||||
py_hashlib = import_fresh_module('hashlib', blocked=['_hashlib'])
|
||||
|
||||
try:
|
||||
from _hashlib import HASH
|
||||
except ImportError:
|
||||
HASH = None
|
||||
|
||||
try:
|
||||
import _blake2
|
||||
except ImportError:
|
||||
|
@ -386,6 +391,9 @@ class HashLibTestCase(unittest.TestCase):
|
|||
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
|
||||
self.assertEqual(capacity + rate, 1600)
|
||||
self.assertEqual(m._capacity_bits, capacity)
|
||||
self.assertEqual(m._rate_bits, rate)
|
||||
|
@ -985,6 +993,10 @@ class KDFTests(unittest.TestCase):
|
|||
hashlib.scrypt(b'password', salt=b'salt', n=2, r=8, p=1,
|
||||
dklen=dklen)
|
||||
|
||||
def test_normalized_name(self):
|
||||
self.assertNotIn("blake2b512", hashlib.algorithms_available)
|
||||
self.assertNotIn("sha3-512", hashlib.algorithms_available)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue