From 867b979b81aba0578d7241d6a38201214a976ace Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Wed, 11 Sep 2013 20:01:10 -0500 Subject: lower ciphername, add api supports, improved assertion message * supports method added to api to check if a ciphername is available. This will be used with skipif (and probably elsewhere) * ciphername lowered. OpenSSL frequently supports aliases for various casing, but reliably supports all lowercase. (e.g. camellia-128-cbc, vs Camellia-128-CBC) * When a cipher is not found an error will now be raised telling you what string cipher it couldn't find. This should probably become a real error like CipherNotFoundError. --- cryptography/bindings/openssl/api.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index 12927782..073cb532 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -72,6 +72,10 @@ class API(object): """ return self.ffi.string(self.lib.OPENSSL_VERSION_TEXT).decode("ascii") + def supports(self, ciphername): + return (self._ffi.NULL != + self._lib.EVP_get_cipherbyname(ciphername.encode("ascii"))) + def create_block_cipher_context(self, cipher, mode): ctx = self.ffi.new("EVP_CIPHER_CTX *") res = self.lib.EVP_CIPHER_CTX_init(ctx) @@ -80,9 +84,10 @@ class API(object): # TODO: compute name using a better algorithm ciphername = "{0}-{1}-{2}".format( cipher.name, cipher.key_size, mode.name - ) - evp_cipher = self.lib.EVP_get_cipherbyname(ciphername.encode("ascii")) - assert evp_cipher != self.ffi.NULL + ).lower() + evp_cipher = self._lib.EVP_get_cipherbyname(ciphername.encode("ascii")) + if evp_cipher == self._ffi.NULL: + raise AssertionError("Unsupported cipher: {0}".format(ciphername)) if isinstance(mode, interfaces.ModeWithInitializationVector): iv_nonce = mode.initialization_vector else: -- cgit v1.2.3 From dff22d4707a50b8164c5c6acd5521bcd91160cd1 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Fri, 27 Sep 2013 13:43:06 -0500 Subject: Camellia block cipher support * Tests for CBC, OFB, CFB, and ECB * Tests will be automatically skipped if camellia support is not present in your OpenSSL library (e.g. OS X 10.8 with default OpenSSL) * Test for unsupported cipher in create_block_cipher_context * Docs for the cipher --- cryptography/primitives/block/ciphers.py | 20 ++++++ docs/primitives/symmetric-encryption.rst | 9 +++ tests/bindings/test_openssl.py | 18 ++++++ tests/primitives/test_ciphers.py | 17 +++++- tests/primitives/test_cryptrec.py | 64 +++++++++++++++++++ tests/primitives/test_openssl_vectors.py | 102 +++++++++++++++++++++++++++++++ 6 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 tests/primitives/test_cryptrec.py create mode 100644 tests/primitives/test_openssl_vectors.py diff --git a/cryptography/primitives/block/ciphers.py b/cryptography/primitives/block/ciphers.py index 01dbd027..1257fc33 100644 --- a/cryptography/primitives/block/ciphers.py +++ b/cryptography/primitives/block/ciphers.py @@ -32,3 +32,23 @@ class AES(object): @property def key_size(self): return len(self.key) * 8 + + +class Camellia(object): + name = "camellia" + block_size = 128 + key_sizes = set([128, 192, 256]) + + def __init__(self, key): + super(Camellia, self).__init__() + self.key = key + + # Verify that the key size matches the expected key size + if self.key_size not in self.key_sizes: + raise ValueError("Invalid key size ({0}) for {1}".format( + self.key_size, self.name + )) + + @property + def key_size(self): + return len(self.key) * 8 diff --git a/docs/primitives/symmetric-encryption.rst b/docs/primitives/symmetric-encryption.rst index 46d7c07c..c4bbf0a5 100644 --- a/docs/primitives/symmetric-encryption.rst +++ b/docs/primitives/symmetric-encryption.rst @@ -51,6 +51,15 @@ Ciphers :param bytes key: The secret key, either ``128``, ``192``, or ``256`` bits. This must be kept secret. +.. class:: cryptography.primitives.block.ciphers.Camellia(key) + + Camellia is a block cipher approved for use by CRYPTREC and ISO/IEC. + It is considered to have comparable security and performance to AES, but + is not as widely studied or deployed. + + :param bytes key: The secret key, either ``128``, ``192``, or ``256`` bits. + This must be kept secret. + Modes ~~~~~ diff --git a/tests/bindings/test_openssl.py b/tests/bindings/test_openssl.py index b23c4ccc..85ecc49c 100644 --- a/tests/bindings/test_openssl.py +++ b/tests/bindings/test_openssl.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import pytest + from cryptography.bindings.openssl.api import api @@ -28,3 +30,19 @@ class TestOpenSSL(object): for every OpenSSL. """ assert api.openssl_version_text().startswith("OpenSSL") + + def test_supports(self): + assert api.supports("not-a-real-cipher") is False + + def test_create_block_cipher_context_with_unsupported_cipher(self): + class FakeCipher(object): + name = "FakeCipher" + key_size = 24 + + class FakeMode(object): + name = "CCC" + + with pytest.raises(AssertionError): + cipher = FakeCipher() + mode = FakeMode() + api.create_block_cipher_context(cipher, mode) diff --git a/tests/primitives/test_ciphers.py b/tests/primitives/test_ciphers.py index 5ee9f223..27d35850 100644 --- a/tests/primitives/test_ciphers.py +++ b/tests/primitives/test_ciphers.py @@ -17,7 +17,7 @@ import binascii import pytest -from cryptography.primitives.block.ciphers import AES +from cryptography.primitives.block.ciphers import AES, Camellia class TestAES(object): @@ -33,3 +33,18 @@ class TestAES(object): def test_invalid_key_size(self): with pytest.raises(ValueError): AES(binascii.unhexlify(b"0" * 12)) + + +class TestCamellia(object): + @pytest.mark.parametrize(("key", "keysize"), [ + (b"0" * 32, 128), + (b"0" * 48, 192), + (b"0" * 64, 256), + ]) + def test_key_size(self, key, keysize): + cipher = Camellia(binascii.unhexlify(key)) + assert cipher.key_size == keysize + + def test_invalid_key_size(self): + with pytest.raises(ValueError): + Camellia(binascii.unhexlify(b"0" * 12)) diff --git a/tests/primitives/test_cryptrec.py b/tests/primitives/test_cryptrec.py new file mode 100644 index 00000000..54ae4d0c --- /dev/null +++ b/tests/primitives/test_cryptrec.py @@ -0,0 +1,64 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Test using the CRYPTREC (Camellia) Test Vectors +""" + +from __future__ import absolute_import, division, print_function + +import binascii +import itertools +import os + +import pytest + +from cryptography.bindings.openssl.api import api +from cryptography.primitives.block import BlockCipher, ciphers, modes + +from ..utils import load_cryptrec_vectors_from_file + +CAMELLIA_ECB_SUPPORTED = api.supports('camellia-128-ecb') + + +def parameterize_encrypt_test(cipher, vector_type, params, fnames): + return pytest.mark.parametrize(params, + list(itertools.chain.from_iterable( + load_cryptrec_vectors_from_file( + os.path.join(cipher, vector_type, fname), + ) + for fname in fnames + )) + ) + + +@pytest.mark.skipif("not CAMELLIA_ECB_SUPPORTED") +class TestCamelliaECB(object): + + @parameterize_encrypt_test( + "Camellia", "NTT", + ("key", "plaintext", "ciphertext"), + [ + "camellia-128-ecb.txt", + "camellia-192-ecb.txt", + "camellia-256-ecb.txt", + ] + ) + def test_NTT(self, key, plaintext, ciphertext): + cipher = BlockCipher( + ciphers.Camellia(binascii.unhexlify(key)), + modes.ECB(), + ) + actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) + actual_ciphertext += cipher.finalize() + assert binascii.hexlify(actual_ciphertext).upper() == ciphertext diff --git a/tests/primitives/test_openssl_vectors.py b/tests/primitives/test_openssl_vectors.py new file mode 100644 index 00000000..0ecbcd9d --- /dev/null +++ b/tests/primitives/test_openssl_vectors.py @@ -0,0 +1,102 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Test using the OpenSSL Test Vectors +""" + +from __future__ import absolute_import, division, print_function + +import binascii +import itertools +import os + +import pytest + +from cryptography.bindings.openssl.api import api +from cryptography.primitives.block import BlockCipher, ciphers, modes + +from ..utils import load_openssl_vectors_from_file + +CAMELLIA_CBC_SUPPORTED = api.supports('camellia-128-cbc') +CAMELLIA_OFB_SUPPORTED = api.supports('camellia-128-ofb') +CAMELLIA_CFB_SUPPORTED = api.supports('camellia-128-cfb') + + +def parameterize_encrypt_test(cipher, params, fnames): + return pytest.mark.parametrize(params, + list(itertools.chain.from_iterable( + load_openssl_vectors_from_file(os.path.join(cipher, fname)) + for fname in fnames + )) + ) + + +@pytest.mark.skipif("not CAMELLIA_CBC_SUPPORTED") +class TestCamelliaCBC(object): + + @parameterize_encrypt_test( + "Camellia", + ("key", "iv", "plaintext", "ciphertext"), + [ + "camellia-cbc.txt", + ] + ) + def test_OpenSSL(self, key, iv, plaintext, ciphertext): + cipher = BlockCipher( + ciphers.Camellia(binascii.unhexlify(key)), + modes.CBC(binascii.unhexlify(iv)), + ) + actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) + actual_ciphertext += cipher.finalize() + assert binascii.hexlify(actual_ciphertext).upper() == ciphertext + + +@pytest.mark.skipif("not CAMELLIA_OFB_SUPPORTED") +class TestCamelliaOFB(object): + + @parameterize_encrypt_test( + "Camellia", + ("key", "iv", "plaintext", "ciphertext"), + [ + "camellia-ofb.txt", + ] + ) + def test_OpenSSL(self, key, iv, plaintext, ciphertext): + cipher = BlockCipher( + ciphers.Camellia(binascii.unhexlify(key)), + modes.OFB(binascii.unhexlify(iv)), + ) + actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) + actual_ciphertext += cipher.finalize() + assert binascii.hexlify(actual_ciphertext).upper() == ciphertext + + +@pytest.mark.skipif("not CAMELLIA_CFB_SUPPORTED") +class TestCamelliaCFB(object): + + @parameterize_encrypt_test( + "Camellia", + ("key", "iv", "plaintext", "ciphertext"), + [ + "camellia-cfb.txt", + ] + ) + def test_OpenSSL(self, key, iv, plaintext, ciphertext): + cipher = BlockCipher( + ciphers.Camellia(binascii.unhexlify(key)), + modes.CFB(binascii.unhexlify(iv)), + ) + actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) + actual_ciphertext += cipher.finalize() + assert binascii.hexlify(actual_ciphertext).upper() == ciphertext -- cgit v1.2.3 From efe0189de0714bbde76082566d0f82df1439cb63 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sat, 28 Sep 2013 13:53:07 -0500 Subject: add pytest.ini with flags to show skipped test reasons, revert tox.ini --- pytest.ini | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..723735ac --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +addopts = -r s -- cgit v1.2.3 From f2ce1ae856e43a292ea7a6aae26d75b508f0a363 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Thu, 3 Oct 2013 21:54:05 -0500 Subject: rebase and modify to support some changed behaviors * Update code to reflect new api object (ffi and lib are no longer private) * tests updated to take an api object * skipif marks removed for now as we need to use the api passed to each individual test. skip testing done inside the test * changed name of supports in api to supports_cipher (future PRs will contain supports_hash) --- cryptography/bindings/openssl/api.py | 11 +++++------ tests/bindings/test_openssl.py | 19 ++----------------- tests/primitives/test_cryptrec.py | 10 ++++------ tests/primitives/test_openssl_vectors.py | 13 ++++++------- 4 files changed, 17 insertions(+), 36 deletions(-) diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py index 073cb532..c352d3b2 100644 --- a/cryptography/bindings/openssl/api.py +++ b/cryptography/bindings/openssl/api.py @@ -72,9 +72,9 @@ class API(object): """ return self.ffi.string(self.lib.OPENSSL_VERSION_TEXT).decode("ascii") - def supports(self, ciphername): - return (self._ffi.NULL != - self._lib.EVP_get_cipherbyname(ciphername.encode("ascii"))) + def supports_cipher(self, ciphername): + return (self.ffi.NULL != + self.lib.EVP_get_cipherbyname(ciphername.encode("ascii"))) def create_block_cipher_context(self, cipher, mode): ctx = self.ffi.new("EVP_CIPHER_CTX *") @@ -85,9 +85,8 @@ class API(object): ciphername = "{0}-{1}-{2}".format( cipher.name, cipher.key_size, mode.name ).lower() - evp_cipher = self._lib.EVP_get_cipherbyname(ciphername.encode("ascii")) - if evp_cipher == self._ffi.NULL: - raise AssertionError("Unsupported cipher: {0}".format(ciphername)) + evp_cipher = self.lib.EVP_get_cipherbyname(ciphername.encode("ascii")) + assert evp_cipher != self.ffi.NULL if isinstance(mode, interfaces.ModeWithInitializationVector): iv_nonce = mode.initialization_vector else: diff --git a/tests/bindings/test_openssl.py b/tests/bindings/test_openssl.py index 85ecc49c..e5b78d18 100644 --- a/tests/bindings/test_openssl.py +++ b/tests/bindings/test_openssl.py @@ -11,8 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest - from cryptography.bindings.openssl.api import api @@ -31,18 +29,5 @@ class TestOpenSSL(object): """ assert api.openssl_version_text().startswith("OpenSSL") - def test_supports(self): - assert api.supports("not-a-real-cipher") is False - - def test_create_block_cipher_context_with_unsupported_cipher(self): - class FakeCipher(object): - name = "FakeCipher" - key_size = 24 - - class FakeMode(object): - name = "CCC" - - with pytest.raises(AssertionError): - cipher = FakeCipher() - mode = FakeMode() - api.create_block_cipher_context(cipher, mode) + def test_supports_cipher(self): + assert api.supports_cipher("not-a-real-cipher") is False diff --git a/tests/primitives/test_cryptrec.py b/tests/primitives/test_cryptrec.py index 54ae4d0c..fb2bf19a 100644 --- a/tests/primitives/test_cryptrec.py +++ b/tests/primitives/test_cryptrec.py @@ -23,13 +23,10 @@ import os import pytest -from cryptography.bindings.openssl.api import api from cryptography.primitives.block import BlockCipher, ciphers, modes from ..utils import load_cryptrec_vectors_from_file -CAMELLIA_ECB_SUPPORTED = api.supports('camellia-128-ecb') - def parameterize_encrypt_test(cipher, vector_type, params, fnames): return pytest.mark.parametrize(params, @@ -42,9 +39,7 @@ def parameterize_encrypt_test(cipher, vector_type, params, fnames): ) -@pytest.mark.skipif("not CAMELLIA_ECB_SUPPORTED") class TestCamelliaECB(object): - @parameterize_encrypt_test( "Camellia", "NTT", ("key", "plaintext", "ciphertext"), @@ -54,10 +49,13 @@ class TestCamelliaECB(object): "camellia-256-ecb.txt", ] ) - def test_NTT(self, key, plaintext, ciphertext): + def test_NTT(self, key, plaintext, ciphertext, api): + if not api.supports_cipher('camellia-128-ecb'): + pytest.skip() cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), modes.ECB(), + api ) actual_ciphertext = cipher.encrypt(binascii.unhexlify(plaintext)) actual_ciphertext += cipher.finalize() diff --git a/tests/primitives/test_openssl_vectors.py b/tests/primitives/test_openssl_vectors.py index 0ecbcd9d..ccd07194 100644 --- a/tests/primitives/test_openssl_vectors.py +++ b/tests/primitives/test_openssl_vectors.py @@ -28,10 +28,6 @@ from cryptography.primitives.block import BlockCipher, ciphers, modes from ..utils import load_openssl_vectors_from_file -CAMELLIA_CBC_SUPPORTED = api.supports('camellia-128-cbc') -CAMELLIA_OFB_SUPPORTED = api.supports('camellia-128-ofb') -CAMELLIA_CFB_SUPPORTED = api.supports('camellia-128-cfb') - def parameterize_encrypt_test(cipher, params, fnames): return pytest.mark.parametrize(params, @@ -42,7 +38,6 @@ def parameterize_encrypt_test(cipher, params, fnames): ) -@pytest.mark.skipif("not CAMELLIA_CBC_SUPPORTED") class TestCamelliaCBC(object): @parameterize_encrypt_test( @@ -53,6 +48,8 @@ class TestCamelliaCBC(object): ] ) def test_OpenSSL(self, key, iv, plaintext, ciphertext): + if not api.supports_cipher('camellia-128-cbc'): + pytest.skip() cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), modes.CBC(binascii.unhexlify(iv)), @@ -62,7 +59,6 @@ class TestCamelliaCBC(object): assert binascii.hexlify(actual_ciphertext).upper() == ciphertext -@pytest.mark.skipif("not CAMELLIA_OFB_SUPPORTED") class TestCamelliaOFB(object): @parameterize_encrypt_test( @@ -73,6 +69,8 @@ class TestCamelliaOFB(object): ] ) def test_OpenSSL(self, key, iv, plaintext, ciphertext): + if not api.supports_cipher('camellia-128-ofb'): + pytest.skip() cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), modes.OFB(binascii.unhexlify(iv)), @@ -82,7 +80,6 @@ class TestCamelliaOFB(object): assert binascii.hexlify(actual_ciphertext).upper() == ciphertext -@pytest.mark.skipif("not CAMELLIA_CFB_SUPPORTED") class TestCamelliaCFB(object): @parameterize_encrypt_test( @@ -93,6 +90,8 @@ class TestCamelliaCFB(object): ] ) def test_OpenSSL(self, key, iv, plaintext, ciphertext): + if not api.supports_cipher('camellia-128-cfb'): + pytest.skip() cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), modes.CFB(binascii.unhexlify(iv)), -- cgit v1.2.3 From 84bb1bb2c04c8e05a072587f9e622f6a5e99de56 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sun, 6 Oct 2013 12:24:47 -0500 Subject: remove openssl api dependency in test_openssl_vectors Update some single quotes to double for consistency --- tests/primitives/test_cryptrec.py | 4 ++-- tests/primitives/test_openssl_vectors.py | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/primitives/test_cryptrec.py b/tests/primitives/test_cryptrec.py index fb2bf19a..de26ebd2 100644 --- a/tests/primitives/test_cryptrec.py +++ b/tests/primitives/test_cryptrec.py @@ -50,8 +50,8 @@ class TestCamelliaECB(object): ] ) def test_NTT(self, key, plaintext, ciphertext, api): - if not api.supports_cipher('camellia-128-ecb'): - pytest.skip() + if not api.supports_cipher("camellia-128-ecb"): + pytest.skip("Does not support Camellia ECB") cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), modes.ECB(), diff --git a/tests/primitives/test_openssl_vectors.py b/tests/primitives/test_openssl_vectors.py index ccd07194..acb982a5 100644 --- a/tests/primitives/test_openssl_vectors.py +++ b/tests/primitives/test_openssl_vectors.py @@ -23,7 +23,6 @@ import os import pytest -from cryptography.bindings.openssl.api import api from cryptography.primitives.block import BlockCipher, ciphers, modes from ..utils import load_openssl_vectors_from_file @@ -47,9 +46,9 @@ class TestCamelliaCBC(object): "camellia-cbc.txt", ] ) - def test_OpenSSL(self, key, iv, plaintext, ciphertext): - if not api.supports_cipher('camellia-128-cbc'): - pytest.skip() + def test_OpenSSL(self, key, iv, plaintext, ciphertext, api): + if not api.supports_cipher("camellia-128-cbc"): + pytest.skip("Does not support Camellia CBC") cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), modes.CBC(binascii.unhexlify(iv)), @@ -68,9 +67,9 @@ class TestCamelliaOFB(object): "camellia-ofb.txt", ] ) - def test_OpenSSL(self, key, iv, plaintext, ciphertext): - if not api.supports_cipher('camellia-128-ofb'): - pytest.skip() + def test_OpenSSL(self, key, iv, plaintext, ciphertext, api): + if not api.supports_cipher("camellia-128-ofb"): + pytest.skip("Does not support Camellia OFB") cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), modes.OFB(binascii.unhexlify(iv)), @@ -89,9 +88,9 @@ class TestCamelliaCFB(object): "camellia-cfb.txt", ] ) - def test_OpenSSL(self, key, iv, plaintext, ciphertext): - if not api.supports_cipher('camellia-128-cfb'): - pytest.skip() + def test_OpenSSL(self, key, iv, plaintext, ciphertext, api): + if not api.supports_cipher("camellia-128-cfb"): + pytest.skip("Does not support Camellia CFB") cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), modes.CFB(binascii.unhexlify(iv)), -- cgit v1.2.3 From 72a6ff5a339e4f83fd00dfc893f5fecefe01dc36 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sun, 6 Oct 2013 17:31:04 -0500 Subject: change camellia keysize to frozenset to match recent PR --- cryptography/primitives/block/ciphers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cryptography/primitives/block/ciphers.py b/cryptography/primitives/block/ciphers.py index 1257fc33..4ac150a4 100644 --- a/cryptography/primitives/block/ciphers.py +++ b/cryptography/primitives/block/ciphers.py @@ -37,7 +37,7 @@ class AES(object): class Camellia(object): name = "camellia" block_size = 128 - key_sizes = set([128, 192, 256]) + key_sizes = frozenset([128, 192, 256]) def __init__(self, key): super(Camellia, self).__init__() -- cgit v1.2.3 From 20034b110a9e8b4e0b539bd0b8e28aa510ec9afc Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 15 Oct 2013 19:10:53 -0500 Subject: add pragma: no cover to handle coverage in the tests for the moment --- tests/primitives/test_cryptrec.py | 2 +- tests/primitives/test_openssl_vectors.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/primitives/test_cryptrec.py b/tests/primitives/test_cryptrec.py index de26ebd2..121e62cb 100644 --- a/tests/primitives/test_cryptrec.py +++ b/tests/primitives/test_cryptrec.py @@ -50,7 +50,7 @@ class TestCamelliaECB(object): ] ) def test_NTT(self, key, plaintext, ciphertext, api): - if not api.supports_cipher("camellia-128-ecb"): + if not api.supports_cipher("camellia-128-ecb"): # pragma: no cover pytest.skip("Does not support Camellia ECB") cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), diff --git a/tests/primitives/test_openssl_vectors.py b/tests/primitives/test_openssl_vectors.py index acb982a5..d30efa5c 100644 --- a/tests/primitives/test_openssl_vectors.py +++ b/tests/primitives/test_openssl_vectors.py @@ -48,7 +48,7 @@ class TestCamelliaCBC(object): ) def test_OpenSSL(self, key, iv, plaintext, ciphertext, api): if not api.supports_cipher("camellia-128-cbc"): - pytest.skip("Does not support Camellia CBC") + pytest.skip("Does not support Camellia CBC") # pragma: no cover cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), modes.CBC(binascii.unhexlify(iv)), @@ -69,7 +69,7 @@ class TestCamelliaOFB(object): ) def test_OpenSSL(self, key, iv, plaintext, ciphertext, api): if not api.supports_cipher("camellia-128-ofb"): - pytest.skip("Does not support Camellia OFB") + pytest.skip("Does not support Camellia OFB") # pragma: no cover cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), modes.OFB(binascii.unhexlify(iv)), @@ -90,7 +90,7 @@ class TestCamelliaCFB(object): ) def test_OpenSSL(self, key, iv, plaintext, ciphertext, api): if not api.supports_cipher("camellia-128-cfb"): - pytest.skip("Does not support Camellia CFB") + pytest.skip("Does not support Camellia CFB") # pragma: no cover cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), modes.CFB(binascii.unhexlify(iv)), -- cgit v1.2.3 From f54277876b76c867af3ad121bae7581b765fcb7c Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 15 Oct 2013 20:02:10 -0500 Subject: use the pragmas consistently. --- tests/primitives/test_cryptrec.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/primitives/test_cryptrec.py b/tests/primitives/test_cryptrec.py index 121e62cb..c30bda48 100644 --- a/tests/primitives/test_cryptrec.py +++ b/tests/primitives/test_cryptrec.py @@ -50,8 +50,8 @@ class TestCamelliaECB(object): ] ) def test_NTT(self, key, plaintext, ciphertext, api): - if not api.supports_cipher("camellia-128-ecb"): # pragma: no cover - pytest.skip("Does not support Camellia ECB") + if not api.supports_cipher("camellia-128-ecb"): + pytest.skip("Does not support Camellia ECB") # pragma: no cover cipher = BlockCipher( ciphers.Camellia(binascii.unhexlify(key)), modes.ECB(), -- cgit v1.2.3