aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregory Haynes <greg@greghaynes.net>2014-12-30 10:31:20 -0800
committerGregory Haynes <greg@greghaynes.net>2014-12-30 10:34:59 -0800
commit6829d7e54a72590cdc0d0af09d908a795df22d0a (patch)
treeb8b0e81501b5de16f13b5b89d5660286fad4f964
parent0d7aead176dbda689623be89cee68d0649e2aea4 (diff)
downloadcryptography-6829d7e54a72590cdc0d0af09d908a795df22d0a.tar.gz
cryptography-6829d7e54a72590cdc0d0af09d908a795df22d0a.tar.bz2
cryptography-6829d7e54a72590cdc0d0af09d908a795df22d0a.zip
Start splitting out interfaces with ciphers
The interfaces module is getting unwieldy so starting to split this out. Beginning by creating a ciphers module. This starts implementing issue #1495
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/__init__.py (renamed from src/cryptography/hazmat/primitives/interfaces.py)73
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/ciphers.py67
2 files changed, 82 insertions, 58 deletions
diff --git a/src/cryptography/hazmat/primitives/interfaces.py b/src/cryptography/hazmat/primitives/interfaces/__init__.py
index 76616e1f..6dedd1f8 100644
--- a/src/cryptography/hazmat/primitives/interfaces.py
+++ b/src/cryptography/hazmat/primitives/interfaces/__init__.py
@@ -4,67 +4,24 @@
from __future__ import absolute_import, division, print_function
-import abc
-
import six
+import abc
-@six.add_metaclass(abc.ABCMeta)
-class CipherAlgorithm(object):
- @abc.abstractproperty
- def name(self):
- """
- A string naming this mode (e.g. "AES", "Camellia").
- """
-
- @abc.abstractproperty
- def key_size(self):
- """
- The size of the key being used as an integer in bits (e.g. 128, 256).
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class BlockCipherAlgorithm(object):
- @abc.abstractproperty
- def block_size(self):
- """
- The size of a block as an integer in bits (e.g. 64, 128).
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class Mode(object):
- @abc.abstractproperty
- def name(self):
- """
- A string naming this mode (e.g. "ECB", "CBC").
- """
-
- @abc.abstractmethod
- def validate_for_algorithm(self, algorithm):
- """
- Checks that all the necessary invariants of this (mode, algorithm)
- combination are met.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class ModeWithInitializationVector(object):
- @abc.abstractproperty
- def initialization_vector(self):
- """
- The value of the initialization vector for this mode as bytes.
- """
-
-
-@six.add_metaclass(abc.ABCMeta)
-class ModeWithNonce(object):
- @abc.abstractproperty
- def nonce(self):
- """
- The value of the nonce for this mode as bytes.
- """
+from cryptography.hazmat.primitives.interfaces.ciphers import (
+ BlockCipherAlgorithm,
+ CipherAlgorithm,
+ Mode,
+ ModeWithInitializationVector,
+ ModeWithNonce)
+
+__all__ = [
+ "BlockCipherAlgorithm",
+ "CipherAlgorithm",
+ "Mode",
+ "ModeWithInitializationVector",
+ "ModeWithNonce"
+]
@six.add_metaclass(abc.ABCMeta)
diff --git a/src/cryptography/hazmat/primitives/interfaces/ciphers.py b/src/cryptography/hazmat/primitives/interfaces/ciphers.py
new file mode 100644
index 00000000..df6d5f74
--- /dev/null
+++ b/src/cryptography/hazmat/primitives/interfaces/ciphers.py
@@ -0,0 +1,67 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
+
+import abc
+
+import six
+
+
+@six.add_metaclass(abc.ABCMeta)
+class CipherAlgorithm(object):
+ @abc.abstractproperty
+ def name(self):
+ """
+ A string naming this mode (e.g. "AES", "Camellia").
+ """
+
+ @abc.abstractproperty
+ def key_size(self):
+ """
+ The size of the key being used as an integer in bits (e.g. 128, 256).
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class BlockCipherAlgorithm(object):
+ @abc.abstractproperty
+ def block_size(self):
+ """
+ The size of a block as an integer in bits (e.g. 64, 128).
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class Mode(object):
+ @abc.abstractproperty
+ def name(self):
+ """
+ A string naming this mode (e.g. "ECB", "CBC").
+ """
+
+ @abc.abstractmethod
+ def validate_for_algorithm(self, algorithm):
+ """
+ Checks that all the necessary invariants of this (mode, algorithm)
+ combination are met.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class ModeWithInitializationVector(object):
+ @abc.abstractproperty
+ def initialization_vector(self):
+ """
+ The value of the initialization vector for this mode as bytes.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class ModeWithNonce(object):
+ @abc.abstractproperty
+ def nonce(self):
+ """
+ The value of the nonce for this mode as bytes.
+ """