mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
gh-132388: Increase test coverage for HMAC (#132389)
- Correctly test missing `digestmod` and `digest` parameters. - Test when chunks of length > 2048 are passed to `update()`. - Test one-shot HMAC-BLAKE2.
This commit is contained in:
parent
842ab81517
commit
9634085af3
2 changed files with 156 additions and 53 deletions
|
|
@ -81,13 +81,13 @@ class HMAC:
|
|||
try:
|
||||
self._init_openssl_hmac(key, msg, digestmod)
|
||||
return
|
||||
except _hashopenssl.UnsupportedDigestmodError:
|
||||
except _hashopenssl.UnsupportedDigestmodError: # pragma: no cover
|
||||
pass
|
||||
if _hmac and isinstance(digestmod, str):
|
||||
try:
|
||||
self._init_builtin_hmac(key, msg, digestmod)
|
||||
return
|
||||
except _hmac.UnknownHashError:
|
||||
except _hmac.UnknownHashError: # pragma: no cover
|
||||
pass
|
||||
self._init_old(key, msg, digestmod)
|
||||
|
||||
|
|
@ -121,12 +121,12 @@ class HMAC:
|
|||
warnings.warn(f"block_size of {blocksize} seems too small; "
|
||||
f"using our default of {self.blocksize}.",
|
||||
RuntimeWarning, 2)
|
||||
blocksize = self.blocksize
|
||||
blocksize = self.blocksize # pragma: no cover
|
||||
else:
|
||||
warnings.warn("No block_size attribute on given digest object; "
|
||||
f"Assuming {self.blocksize}.",
|
||||
RuntimeWarning, 2)
|
||||
blocksize = self.blocksize
|
||||
blocksize = self.blocksize # pragma: no cover
|
||||
|
||||
if len(key) > blocksize:
|
||||
key = digest_cons(key).digest()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue