Skip to content

Commit d3bcecd

Browse files
[3.13] gh-135571: Guard _hashlib usage in test_hashlib.py (GH-135572) (#136041)
(cherry picked from commit 065194c) Co-authored-by: Will Childs-Klein <willck93@gmail.com>
1 parent ad1b0c9 commit d3bcecd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Lib/test/test_hashlib.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ def test_clinic_signature(self):
264264
hashlib.new(digest_name, b'')
265265
hashlib.new(digest_name, data=b'')
266266
hashlib.new(digest_name, string=b'')
267-
if self._hashlib:
267+
# Make sure that _hashlib contains the constructor
268+
# to test when using a combination of libcrypto and
269+
# interned hash implementations.
270+
if self._hashlib and digest_name in self._hashlib._constructors:
268271
self._hashlib.new(digest_name, b'')
269272
self._hashlib.new(digest_name, data=b'')
270273
self._hashlib.new(digest_name, string=b'')
@@ -316,7 +319,8 @@ def test_clinic_signature_errors(self):
316319
with self.subTest(digest_name, args=args, kwds=kwds):
317320
with self.assertRaisesRegex(TypeError, errmsg):
318321
hashlib.new(digest_name, *args, **kwds)
319-
if self._hashlib:
322+
if (self._hashlib and
323+
digest_name in self._hashlib._constructors):
320324
with self.assertRaisesRegex(TypeError, errmsg):
321325
self._hashlib.new(digest_name, *args, **kwds)
322326

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy