Block OpenSSL HMAC-HASH one-shot digest implementation.
(blocked_name)
| 883 | |
| 884 | |
| 885 | def _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 | |
| 903 | def _block_builtin_hash_new(name): |
no test coverage detected
searching dependent graphs…