Check that HMAC(key, msg) == digest. This also tests that using an empty/None initial message and then calling `h.update(msg)` produces the same result, namely that HMAC(key, msg) is equivalent to HMAC(key).update(msg).
(
self, key, msg, hexdigest, hashname, digest_size, block_size,
hmac_new_func, hmac_new_kwds=frozendict(),
)
| 301 | ) |
| 302 | |
| 303 | def check_hmac_new( |
| 304 | self, key, msg, hexdigest, hashname, digest_size, block_size, |
| 305 | hmac_new_func, hmac_new_kwds=frozendict(), |
| 306 | ): |
| 307 | """Check that HMAC(key, msg) == digest. |
| 308 | |
| 309 | This also tests that using an empty/None initial message and |
| 310 | then calling `h.update(msg)` produces the same result, namely |
| 311 | that HMAC(key, msg) is equivalent to HMAC(key).update(msg). |
| 312 | """ |
| 313 | h = hmac_new_func(key, msg, **hmac_new_kwds) |
| 314 | self.check_object(h, hexdigest, hashname, digest_size, block_size) |
| 315 | |
| 316 | def hmac_new_feed(*args): |
| 317 | h = hmac_new_func(key, *args, **hmac_new_kwds) |
| 318 | h.update(msg) |
| 319 | self.check_hexdigest(h, hexdigest, digest_size) |
| 320 | |
| 321 | with self.subTest('no initial message'): |
| 322 | hmac_new_feed() |
| 323 | with self.subTest('initial message is empty'): |
| 324 | hmac_new_feed(b'') |
| 325 | with self.subTest('initial message is None'): |
| 326 | hmac_new_feed(None) |
| 327 | |
| 328 | def assert_hmac_hexdigest( |
| 329 | self, key, msg, hexdigest, digestmod, digest_size, |
no test coverage detected