Alex Gaynor | a2e1f54 | 2013-08-10 08:59:11 -0400 | [diff] [blame^] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | # you may not use this file except in compliance with the License. |
| 3 | # You may obtain a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 10 | # implied. |
| 11 | # See the License for the specific language governing permissions and |
| 12 | # limitations under the License. |
| 13 | |
Alex Gaynor | 95b8620 | 2013-08-08 19:36:44 -0700 | [diff] [blame] | 14 | import binascii |
| 15 | |
| 16 | import pytest |
| 17 | |
| 18 | from cryptography.primitives.block import BlockCipher, ciphers, modes, padding |
| 19 | |
| 20 | |
| 21 | class TestBlockCipher(object): |
Alex Gaynor | 250903a | 2013-08-09 12:12:30 -0700 | [diff] [blame] | 22 | def test_use_after_finalize(self): |
Alex Gaynor | 95b8620 | 2013-08-08 19:36:44 -0700 | [diff] [blame] | 23 | cipher = BlockCipher( |
Alex Gaynor | 250903a | 2013-08-09 12:12:30 -0700 | [diff] [blame] | 24 | ciphers.AES(binascii.unhexlify(b"0" * 32)), |
| 25 | modes.CBC(binascii.unhexlify(b"0" * 32), padding.NoPadding()) |
Alex Gaynor | 95b8620 | 2013-08-08 19:36:44 -0700 | [diff] [blame] | 26 | ) |
Alex Gaynor | 250903a | 2013-08-09 12:12:30 -0700 | [diff] [blame] | 27 | cipher.encrypt(b"a" * 16) |
| 28 | cipher.finalize() |
| 29 | with pytest.raises(ValueError): |
| 30 | cipher.encrypt(b"b" * 16) |
| 31 | with pytest.raises(ValueError): |
| 32 | cipher.finalize() |