blob: 79d65a0f41416719b99bcd433943f19360e5b377 [file] [log] [blame]
Alex Gaynor95b86202013-08-08 19:36:44 -07001import binascii
2
3import pytest
4
5from cryptography.primitives.block import BlockCipher, ciphers, modes, padding
6
7
8class TestBlockCipher(object):
Alex Gaynor250903a2013-08-09 12:12:30 -07009 def test_use_after_finalize(self):
Alex Gaynor95b86202013-08-08 19:36:44 -070010 cipher = BlockCipher(
Alex Gaynor250903a2013-08-09 12:12:30 -070011 ciphers.AES(binascii.unhexlify(b"0" * 32)),
12 modes.CBC(binascii.unhexlify(b"0" * 32), padding.NoPadding())
Alex Gaynor95b86202013-08-08 19:36:44 -070013 )
Alex Gaynor250903a2013-08-09 12:12:30 -070014 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()