|
27 | 27 | py_hashlib = import_fresh_module('hashlib', blocked=['_hashlib']) |
28 | 28 |
|
29 | 29 | try: |
30 | | - from _hashlib import HASH |
| 30 | + from _hashlib import HASH, HASHXOF |
31 | 31 | except ImportError: |
32 | 32 | HASH = None |
| 33 | + HASHXOF = None |
33 | 34 |
|
34 | 35 | try: |
35 | 36 | import _blake2 |
@@ -254,6 +255,9 @@ def test_digest_length_overflow(self): |
254 | 255 | h = cons() |
255 | 256 | if h.name not in self.shakes: |
256 | 257 | continue |
| 258 | + if HASH is not None and isinstance(h, HASH): |
| 259 | + # _hashopenssl's take a size_t |
| 260 | + continue |
257 | 261 | for digest in h.digest, h.hexdigest: |
258 | 262 | self.assertRaises(ValueError, digest, -10) |
259 | 263 | for length in large_sizes: |
@@ -860,6 +864,18 @@ def hash_in_chunks(chunk_size): |
860 | 864 | def test_get_fips_mode(self): |
861 | 865 | self.assertIsInstance(c_hashlib.get_fips_mode(), int) |
862 | 866 |
|
| 867 | + @unittest.skipUnless(HASH is not None, 'need _hashlib') |
| 868 | + def test_internal_types(self): |
| 869 | + # internal types like _hashlib.HASH are not constructable |
| 870 | + with self.assertRaisesRegex( |
| 871 | + TypeError, "cannot create 'HASH' instance" |
| 872 | + ): |
| 873 | + HASH() |
| 874 | + with self.assertRaisesRegex( |
| 875 | + TypeError, "cannot create 'HASHXOF' instance" |
| 876 | + ): |
| 877 | + HASHXOF() |
| 878 | + |
863 | 879 |
|
864 | 880 | class KDFTests(unittest.TestCase): |
865 | 881 |
|
|
0 commit comments