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