aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/backends/test_commoncrypto.py1
-rw-r--r--tests/hazmat/backends/test_multibackend.py14
-rw-r--r--tests/hazmat/backends/test_openssl.py3
-rw-r--r--tests/hazmat/primitives/test_block.py1
-rw-r--r--tests/hazmat/primitives/test_ec.py11
-rw-r--r--tests/hazmat/primitives/test_hashes.py2
-rw-r--r--tests/hazmat/primitives/test_hmac.py2
-rw-r--r--tests/hazmat/primitives/test_pbkdf2hmac.py2
-rw-r--r--tests/test_interfaces.py68
9 files changed, 96 insertions, 8 deletions
diff --git a/tests/hazmat/backends/test_commoncrypto.py b/tests/hazmat/backends/test_commoncrypto.py
index 28d1a6ca..b79c02e0 100644
--- a/tests/hazmat/backends/test_commoncrypto.py
+++ b/tests/hazmat/backends/test_commoncrypto.py
@@ -30,6 +30,7 @@ from ...utils import raises_unsupported_algorithm
class DummyCipher(object):
name = "dummy-cipher"
block_size = 128
+ key_size = 128
@pytest.mark.skipif("commoncrypto" not in
diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py
index c50b6cf6..39c03146 100644
--- a/tests/hazmat/backends/test_multibackend.py
+++ b/tests/hazmat/backends/test_multibackend.py
@@ -38,15 +38,15 @@ class DummyCipherBackend(object):
def __init__(self, supported_ciphers):
self._ciphers = supported_ciphers
- def cipher_supported(self, algorithm, mode):
- return (type(algorithm), type(mode)) in self._ciphers
+ def cipher_supported(self, cipher, mode):
+ return (type(cipher), type(mode)) in self._ciphers
- def create_symmetric_encryption_ctx(self, algorithm, mode):
- if not self.cipher_supported(algorithm, mode):
+ def create_symmetric_encryption_ctx(self, cipher, mode):
+ if not self.cipher_supported(cipher, mode):
raise UnsupportedAlgorithm("", _Reasons.UNSUPPORTED_CIPHER)
- def create_symmetric_decryption_ctx(self, algorithm, mode):
- if not self.cipher_supported(algorithm, mode):
+ def create_symmetric_decryption_ctx(self, cipher, mode):
+ if not self.cipher_supported(cipher, mode):
raise UnsupportedAlgorithm("", _Reasons.UNSUPPORTED_CIPHER)
@@ -92,7 +92,7 @@ class DummyPBKDF2HMACBackend(object):
@utils.register_interface(RSABackend)
class DummyRSABackend(object):
- def generate_rsa_private_key(self, public_exponent, private_key):
+ def generate_rsa_private_key(self, public_exponent, key_size):
pass
def rsa_padding_supported(self, padding):
diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py
index 3bea413a..83494d0d 100644
--- a/tests/hazmat/backends/test_openssl.py
+++ b/tests/hazmat/backends/test_openssl.py
@@ -51,6 +51,7 @@ class DummyMode(object):
@utils.register_interface(interfaces.CipherAlgorithm)
class DummyCipher(object):
name = "dummy-cipher"
+ key_size = 128
@utils.register_interface(interfaces.AsymmetricPadding)
@@ -61,6 +62,8 @@ class DummyPadding(object):
@utils.register_interface(interfaces.HashAlgorithm)
class DummyHash(object):
name = "dummy-hash"
+ block_size = 128
+ digest_size = 128
class DummyMGF(object):
diff --git a/tests/hazmat/primitives/test_block.py b/tests/hazmat/primitives/test_block.py
index 022e3af7..0b90dd90 100644
--- a/tests/hazmat/primitives/test_block.py
+++ b/tests/hazmat/primitives/test_block.py
@@ -43,6 +43,7 @@ class DummyMode(object):
@utils.register_interface(interfaces.CipherAlgorithm)
class DummyCipher(object):
name = "dummy-cipher"
+ key_size = 128
@pytest.mark.cipher
diff --git a/tests/hazmat/primitives/test_ec.py b/tests/hazmat/primitives/test_ec.py
index 1b3bb9b3..9ed762cb 100644
--- a/tests/hazmat/primitives/test_ec.py
+++ b/tests/hazmat/primitives/test_ec.py
@@ -68,11 +68,20 @@ class DummyCurve(object):
@utils.register_interface(interfaces.EllipticCurveSignatureAlgorithm)
class DummySignatureAlgorithm(object):
- pass
+ algorithm = None
@utils.register_interface(EllipticCurveBackend)
class DeprecatedDummyECBackend(object):
+ def _unimplemented(self):
+ raise NotImplementedError
+
+ elliptic_curve_signature_algorithm_supported = _unimplemented
+ load_elliptic_curve_private_numbers = _unimplemented
+ load_elliptic_curve_public_numbers = _unimplemented
+ elliptic_curve_supported = _unimplemented
+ generate_elliptic_curve_private_key = _unimplemented
+
def elliptic_curve_private_key_from_numbers(self, numbers):
return b"private_key"
diff --git a/tests/hazmat/primitives/test_hashes.py b/tests/hazmat/primitives/test_hashes.py
index ffd65bde..2bf1f8ef 100644
--- a/tests/hazmat/primitives/test_hashes.py
+++ b/tests/hazmat/primitives/test_hashes.py
@@ -33,6 +33,8 @@ from ...utils import raises_unsupported_algorithm
@utils.register_interface(interfaces.HashAlgorithm)
class UnsupportedDummyHash(object):
name = "unsupported-dummy-hash"
+ block_size = 128
+ digest_size = 128
@pytest.mark.hash
diff --git a/tests/hazmat/primitives/test_hmac.py b/tests/hazmat/primitives/test_hmac.py
index dca3eb02..21be73a3 100644
--- a/tests/hazmat/primitives/test_hmac.py
+++ b/tests/hazmat/primitives/test_hmac.py
@@ -33,6 +33,8 @@ from ...utils import raises_unsupported_algorithm
@utils.register_interface(interfaces.HashAlgorithm)
class UnsupportedDummyHash(object):
name = "unsupported-dummy-hash"
+ block_size = 128
+ digest_size = 128
@pytest.mark.supported(
diff --git a/tests/hazmat/primitives/test_pbkdf2hmac.py b/tests/hazmat/primitives/test_pbkdf2hmac.py
index e928fc6a..fa925877 100644
--- a/tests/hazmat/primitives/test_pbkdf2hmac.py
+++ b/tests/hazmat/primitives/test_pbkdf2hmac.py
@@ -31,6 +31,8 @@ from ...utils import raises_unsupported_algorithm
@utils.register_interface(interfaces.HashAlgorithm)
class DummyHash(object):
name = "dummy-hash"
+ block_size = 128
+ digest_size = 128
class TestPBKDF2HMAC(object):
diff --git a/tests/test_interfaces.py b/tests/test_interfaces.py
new file mode 100644
index 00000000..0c72ad33
--- /dev/null
+++ b/tests/test_interfaces.py
@@ -0,0 +1,68 @@
+# 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.
+
+import abc
+
+import pytest
+
+import six
+
+from cryptography.utils import (
+ InterfaceNotImplemented, register_interface, verify_interface
+)
+
+
+class TestVerifyInterface(object):
+ def test_verify_missing_method(self):
+ @six.add_metaclass(abc.ABCMeta)
+ class SimpleInterface(object):
+ @abc.abstractmethod
+ def method(self):
+ """A simple method"""
+
+ @register_interface(SimpleInterface)
+ class NonImplementer(object):
+ pass
+
+ with pytest.raises(InterfaceNotImplemented):
+ verify_interface(SimpleInterface, NonImplementer)
+
+ def test_different_arguments(self):
+ @six.add_metaclass(abc.ABCMeta)
+ class SimpleInterface(object):
+ @abc.abstractmethod
+ def method(self, a):
+ """Method with one argument"""
+
+ @register_interface(SimpleInterface)
+ class NonImplementer(object):
+ def method(self):
+ """Method with no arguments"""
+
+ with pytest.raises(InterfaceNotImplemented):
+ verify_interface(SimpleInterface, NonImplementer)
+
+ def test_handles_abstract_property(self):
+ @six.add_metaclass(abc.ABCMeta)
+ class SimpleInterface(object):
+ @abc.abstractproperty
+ def property(self):
+ """An abstract property"""
+
+ @register_interface(SimpleInterface)
+ class NonImplementer(object):
+ @property
+ def property(self):
+ """A concrete property"""
+
+ verify_interface(SimpleInterface, NonImplementer)