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

Function _block_openssl_hmac_new

Lib/test/support/hashlib_helper.py:867–882  ·  view source on GitHub ↗

Block OpenSSL HMAC-HASH implementation.

(blocked_name)

Source from the content-addressed store, hash-verified

865
866
867def _block_openssl_hmac_new(blocked_name):
868 """Block OpenSSL HMAC-HASH implementation."""
869 assert isinstance(blocked_name, str), blocked_name
870
871 # re-import '_hashlib' in case it was mocked
872 if (_hashlib := _import_module("_hashlib")) is None:
873 return contextlib.nullcontext()
874
875 @functools.wraps(wrapped := _hashlib.hmac_new)
876 def wrapper(key, msg=b'', digestmod=None):
877 if digestmod == blocked_name:
878 raise _hashlib.UnsupportedDigestmodError(blocked_name)
879 return wrapped(key, msg, digestmod)
880
881 _ensure_wrapper_signature(wrapper, wrapped)
882 return unittest.mock.patch('_hashlib.hmac_new', wrapper)
883
884
885def _block_openssl_hmac_digest(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…