Alex Gaynor | 95b8620 | 2013-08-08 19:36:44 -0700 | [diff] [blame] | 1 | import binascii |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | from cryptography.primitives.block import BlockCipher, ciphers, modes, padding |
| 6 | |
| 7 | |
| 8 | class TestBlockCipher(object): |
Alex Gaynor | 250903a | 2013-08-09 12:12:30 -0700 | [diff] [blame^] | 9 | def test_use_after_finalize(self): |
Alex Gaynor | 95b8620 | 2013-08-08 19:36:44 -0700 | [diff] [blame] | 10 | cipher = BlockCipher( |
Alex Gaynor | 250903a | 2013-08-09 12:12:30 -0700 | [diff] [blame^] | 11 | ciphers.AES(binascii.unhexlify(b"0" * 32)), |
| 12 | modes.CBC(binascii.unhexlify(b"0" * 32), padding.NoPadding()) |
Alex Gaynor | 95b8620 | 2013-08-08 19:36:44 -0700 | [diff] [blame] | 13 | ) |
Alex Gaynor | 250903a | 2013-08-09 12:12:30 -0700 | [diff] [blame^] | 14 | cipher.encrypt(b"a" * 16) |
| 15 | cipher.finalize() |
| 16 | with pytest.raises(ValueError): |
| 17 | cipher.encrypt(b"b" * 16) |
| 18 | with pytest.raises(ValueError): |
| 19 | cipher.finalize() |