Donald Stufft | 93e768b | 2013-08-10 15:10:38 -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 | |
Hynek Schlawack | 425f584 | 2013-08-11 09:54:59 +0200 | [diff] [blame] | 14 | from __future__ import absolute_import, division, print_function |
| 15 | |
Donald Stufft | 93e768b | 2013-08-10 15:10:38 -0400 | [diff] [blame] | 16 | import binascii |
| 17 | |
| 18 | import pytest |
| 19 | |
Paul Kehrer | dff22d4 | 2013-09-27 13:43:06 -0500 | [diff] [blame^] | 20 | from cryptography.primitives.block.ciphers import AES, Camellia |
Donald Stufft | 93e768b | 2013-08-10 15:10:38 -0400 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class TestAES(object): |
| 24 | @pytest.mark.parametrize(("key", "keysize"), [ |
| 25 | (b"0" * 32, 128), |
| 26 | (b"0" * 48, 192), |
| 27 | (b"0" * 64, 256), |
| 28 | ]) |
| 29 | def test_key_size(self, key, keysize): |
| 30 | cipher = AES(binascii.unhexlify(key)) |
| 31 | assert cipher.key_size == keysize |
Donald Stufft | ad89af1 | 2013-08-10 16:01:56 -0400 | [diff] [blame] | 32 | |
| 33 | def test_invalid_key_size(self): |
| 34 | with pytest.raises(ValueError): |
| 35 | AES(binascii.unhexlify(b"0" * 12)) |
Paul Kehrer | dff22d4 | 2013-09-27 13:43:06 -0500 | [diff] [blame^] | 36 | |
| 37 | |
| 38 | class TestCamellia(object): |
| 39 | @pytest.mark.parametrize(("key", "keysize"), [ |
| 40 | (b"0" * 32, 128), |
| 41 | (b"0" * 48, 192), |
| 42 | (b"0" * 64, 256), |
| 43 | ]) |
| 44 | def test_key_size(self, key, keysize): |
| 45 | cipher = Camellia(binascii.unhexlify(key)) |
| 46 | assert cipher.key_size == keysize |
| 47 | |
| 48 | def test_invalid_key_size(self): |
| 49 | with pytest.raises(ValueError): |
| 50 | Camellia(binascii.unhexlify(b"0" * 12)) |