MCPcopy Index your code
hub / github.com/python/cpython / _block_openssl_hash_new

Function _block_openssl_hash_new

Lib/test/support/hashlib_helper.py:848–864  ·  view source on GitHub ↗

Block OpenSSL implementation of _hashlib.new().

(blocked_name)

Source from the content-addressed store, hash-verified

846
847
848def _block_openssl_hash_new(blocked_name):
849 """Block OpenSSL implementation of _hashlib.new()."""
850 assert isinstance(blocked_name, str), blocked_name
851
852 # re-import '_hashlib' in case it was mocked
853 if (_hashlib := _import_module("_hashlib")) is None:
854 return contextlib.nullcontext()
855
856 @functools.wraps(wrapped := _hashlib.new)
857 def _hashlib_new(name, data=b'', *, usedforsecurity=True, string=None):
858 if name == blocked_name:
859 raise _hashlib.UnsupportedDigestmodError(blocked_name)
860 return wrapped(name, data,
861 usedforsecurity=usedforsecurity, string=string)
862
863 _ensure_wrapper_signature(_hashlib_new, wrapped)
864 return unittest.mock.patch('_hashlib.new', _hashlib_new)
865
866
867def _block_openssl_hmac_new(blocked_name):

Callers 1

block_algorithmFunction · 0.85

Calls 2

_import_moduleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…