MCPcopy Create free account
hub / github.com/python/cpython / hmac_new_by_name

Method hmac_new_by_name

Lib/test/test_hmac.py:208–222  ·  view source on GitHub ↗

Alternative implementation of hmac_new(). This is typically useful when one needs to test against an HMAC implementation which only recognizes underlying hash functions by their name (all HMAC implementations must at least recognize hash functions by their names but

(self, key, msg=None, *, hashname)

Source from the content-addressed store, hash-verified

206 """Mixin class for common tests."""
207
208 def hmac_new_by_name(self, key, msg=None, *, hashname):
209 """Alternative implementation of hmac_new().
210
211 This is typically useful when one needs to test against an HMAC
212 implementation which only recognizes underlying hash functions
213 by their name (all HMAC implementations must at least recognize
214 hash functions by their names but some may use aliases such as
215 `hashlib.sha1` instead of "sha1").
216
217 Unlike hmac_new(), this method may assert the type of 'hashname'
218 as it should only be used in tests that are expected to create
219 a HMAC object.
220 """
221 self.assertIsInstance(hashname, str)
222 return self.hmac_new(key, msg, digestmod=hashname)
223
224 def hmac_digest_by_name(self, key, msg=None, *, hashname):
225 """Alternative implementation of hmac_digest().

Callers 1

Calls 2

assertIsInstanceMethod · 0.80
hmac_newMethod · 0.45

Tested by

no test coverage detected