Check that HMAC(key, msg) == digest. The 'hashfunc' and 'hashname' are used as 'digestmod' values, thereby allowing to test the underlying dispatching mechanism. Note that 'hashfunc' may be a string, a callable, or a PEP-257 module. Note that not all HMAC implementa
(
self, key, msg, hexdigest, hashfunc, hashname, digest_size, block_size
)
| 232 | return self.hmac_digest(key, msg, digestmod=hashname) |
| 233 | |
| 234 | def assert_hmac( |
| 235 | self, key, msg, hexdigest, hashfunc, hashname, digest_size, block_size |
| 236 | ): |
| 237 | """Check that HMAC(key, msg) == digest. |
| 238 | |
| 239 | The 'hashfunc' and 'hashname' are used as 'digestmod' values, |
| 240 | thereby allowing to test the underlying dispatching mechanism. |
| 241 | |
| 242 | Note that 'hashfunc' may be a string, a callable, or a PEP-257 |
| 243 | module. Note that not all HMAC implementations may recognize the |
| 244 | same set of types for 'hashfunc', but they should always accept |
| 245 | a hash function by its name. |
| 246 | """ |
| 247 | if hashfunc == hashname: |
| 248 | choices = [hashname] |
| 249 | else: |
| 250 | choices = [hashfunc, hashname] |
| 251 | |
| 252 | for digestmod in choices: |
| 253 | with self.subTest(digestmod=digestmod): |
| 254 | self.assert_hmac_new( |
| 255 | key, msg, hexdigest, digestmod, |
| 256 | hashname, digest_size, block_size |
| 257 | ) |
| 258 | self.assert_hmac_hexdigest( |
| 259 | key, msg, hexdigest, digestmod, digest_size |
| 260 | ) |
| 261 | self.assert_hmac_common_cases( |
| 262 | key, msg, hexdigest, digestmod, |
| 263 | hashname, digest_size, block_size |
| 264 | ) |
| 265 | self.assert_hmac_extra_cases( |
| 266 | key, msg, hexdigest, digestmod, |
| 267 | hashname, digest_size, block_size |
| 268 | ) |
| 269 | |
| 270 | self.assert_hmac_new_by_name( |
| 271 | key, msg, hexdigest, hashname, digest_size, block_size |
| 272 | ) |
| 273 | self.assert_hmac_hexdigest_by_name( |
| 274 | key, msg, hexdigest, hashname, digest_size |
| 275 | ) |
| 276 | |
| 277 | def assert_hmac_new( |
| 278 | self, key, msg, hexdigest, digestmod, hashname, digest_size, block_size |
no test coverage detected