Block OpenSSL HMAC-HASH implementation.
(blocked_name)
| 865 | |
| 866 | |
| 867 | def _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 | |
| 885 | def _block_openssl_hmac_digest(blocked_name): |
no test coverage detected
searching dependent graphs…