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

Function _block_openssl_hmac_digest

Lib/test/support/hashlib_helper.py:885–900  ·  view source on GitHub ↗

Block OpenSSL HMAC-HASH one-shot digest implementation.

(blocked_name)

Source from the content-addressed store, hash-verified

883
884
885def _block_openssl_hmac_digest(blocked_name):
886 """Block OpenSSL HMAC-HASH one-shot digest implementation."""
887 assert isinstance(blocked_name, str), blocked_name
888
889 # re-import '_hashlib' in case it was mocked
890 if (_hashlib := _import_module("_hashlib")) is None:
891 return contextlib.nullcontext()
892
893 @functools.wraps(wrapped := _hashlib.hmac_digest)
894 def _hashlib_hmac_digest(key, msg, digest):
895 if digest == blocked_name:
896 raise _hashlib.UnsupportedDigestmodError(blocked_name)
897 return wrapped(key, msg, digest)
898
899 _ensure_wrapper_signature(_hashlib_hmac_digest, wrapped)
900 return unittest.mock.patch('_hashlib.hmac_digest', _hashlib_hmac_digest)
901
902
903def _block_builtin_hash_new(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…