blob: 27d35850f16d9a8413c47671ffa1d8bf85b15c9c [file] [log] [blame]
Donald Stufft93e768b2013-08-10 15:10:38 -04001# 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 Schlawack425f5842013-08-11 09:54:59 +020014from __future__ import absolute_import, division, print_function
15
Donald Stufft93e768b2013-08-10 15:10:38 -040016import binascii
17
18import pytest
19
Paul Kehrerdff22d42013-09-27 13:43:06 -050020from cryptography.primitives.block.ciphers import AES, Camellia
Donald Stufft93e768b2013-08-10 15:10:38 -040021
22
23class 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 Stufftad89af12013-08-10 16:01:56 -040032
33 def test_invalid_key_size(self):
34 with pytest.raises(ValueError):
35 AES(binascii.unhexlify(b"0" * 12))
Paul Kehrerdff22d42013-09-27 13:43:06 -050036
37
38class 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))