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

Function digest

Lib/hmac.py:233–266  ·  view source on GitHub ↗

Fast inline implementation of HMAC. key: bytes or buffer, The key for the keyed hash object. msg: bytes or buffer, Input message. digest: A hash name suitable for hashlib.new() for best performance. *OR* A hashlib constructor returning a new hash object. *OR* A m

(key, msg, digest)

Source from the content-addressed store, hash-verified

231
232
233def digest(key, msg, digest):
234 """Fast inline implementation of HMAC.
235
236 key: bytes or buffer, The key for the keyed hash object.
237 msg: bytes or buffer, Input message.
238 digest: A hash name suitable for hashlib.new() for best performance. *OR*
239 A hashlib constructor returning a new hash object. *OR*
240 A module supporting PEP 247.
241 """
242 if _hashopenssl and isinstance(digest, (str, _functype)):
243 try:
244 return _hashopenssl.hmac_digest(key, msg, digest)
245 except OverflowError:
246 # OpenSSL's HMAC limits the size of the key to INT_MAX.
247 # Instead of falling back to HACL* implementation which
248 # may still not be supported due to a too large key, we
249 # directly switch to the pure Python fallback instead
250 # even if we could have used streaming HMAC for small keys
251 # but large messages.
252 return _compute_digest_fallback(key, msg, digest)
253 except _hashopenssl.UnsupportedDigestmodError:
254 pass
255
256 if _hmac and isinstance(digest, str):
257 try:
258 return _hmac.compute_digest(key, msg, digest)
259 except (OverflowError, _hmac.UnknownHashError):
260 # HACL* HMAC limits the size of the key to UINT32_MAX
261 # so we fallback to the pure Python implementation even
262 # if streaming HMAC may have been used for small keys
263 # and large messages.
264 pass
265
266 return _compute_digest_fallback(key, msg, digest)
267
268
269def _compute_digest_fallback(key, msg, digest):

Callers 2

file_digestFunction · 0.85
check_file_digestMethod · 0.85

Calls 2

_compute_digest_fallbackFunction · 0.85
hmac_digestMethod · 0.45

Tested by 1

check_file_digestMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…