(self)
| 1478 | |
| 1479 | @hashlib_helper.requires_hashdigest('sha256') |
| 1480 | def test_legacy_block_size_warnings(self): |
| 1481 | class MockCrazyHash(object): |
| 1482 | """Ain't no block_size attribute here.""" |
| 1483 | def __init__(self, *args): |
| 1484 | self._x = hashlib.sha256(*args) |
| 1485 | self.digest_size = self._x.digest_size |
| 1486 | def update(self, v): |
| 1487 | self._x.update(v) |
| 1488 | def digest(self): |
| 1489 | return self._x.digest() |
| 1490 | |
| 1491 | with warnings.catch_warnings(): |
| 1492 | warnings.simplefilter('error', RuntimeWarning) |
| 1493 | with self.assertRaises(RuntimeWarning): |
| 1494 | hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash) |
| 1495 | self.fail('Expected warning about missing block_size') |
| 1496 | |
| 1497 | MockCrazyHash.block_size = 1 |
| 1498 | with self.assertRaises(RuntimeWarning): |
| 1499 | hmac.HMAC(b'a', b'b', digestmod=MockCrazyHash) |
| 1500 | self.fail('Expected warning about small block_size') |
| 1501 | |
| 1502 | @hashlib_helper.requires_hashdigest('sha256') |
| 1503 | def test_with_fallback(self): |
nothing calls this directly
no test coverage detected