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

Method check_builtin_hmac

Lib/test/test_support.py:934–953  ·  view source on GitHub ↗

Check that HACL* HMAC interface is enabled/disabled.

(self, name, *, disabled=True)

Source from the content-addressed store, hash-verified

932 _ = do_hash(b"")
933
934 def check_builtin_hmac(self, name, *, disabled=True):
935 """Check that HACL* HMAC interface is enabled/disabled."""
936 if name in hashlib_helper.NON_HMAC_DIGEST_NAMES:
937 # HMAC-BLAKE and HMAC-SHAKE raise a ValueError as they are not
938 # supported at all (they do not make any sense in practice).
939 with self.assertRaises(ValueError):
940 self._hmac.compute_digest(b"", b"", name)
941 else:
942 with self.check_context(disabled):
943 _ = self._hmac.compute_digest(b"", b"", name)
944
945 with self.check_context(disabled):
946 _ = self._hmac.new(b"", b"", name)
947
948 if do_hmac := self.fetch_hmac_function(name):
949 self.assertStartsWith(do_hmac.__name__, 'compute_')
950 with self.check_context(disabled):
951 _ = do_hmac(b"", b"")
952 else:
953 self.assertIn(name, hashlib_helper.NON_HMAC_DIGEST_NAMES)
954
955 @support.subTests(
956 ('name', 'allow_openssl', 'allow_builtin'),

Callers 1

test_disable_hashMethod · 0.95

Calls 6

check_contextMethod · 0.95
fetch_hmac_functionMethod · 0.95
assertStartsWithMethod · 0.80
assertInMethod · 0.80
assertRaisesMethod · 0.45
newMethod · 0.45

Tested by

no test coverage detected