diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-02-14 10:27:14 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-02-14 10:36:24 -0600 |
commit | 7c5c9fedd513f4ef66b62fcf5fdcde8dc30fe532 (patch) | |
tree | 1600ea1cdc548421f021bdc79a1251db8a7a0ebf | |
parent | 2129d5035849c69f990a646ac76891d1a886be55 (diff) | |
download | cryptography-7c5c9fedd513f4ef66b62fcf5fdcde8dc30fe532.tar.gz cryptography-7c5c9fedd513f4ef66b62fcf5fdcde8dc30fe532.tar.bz2 cryptography-7c5c9fedd513f4ef66b62fcf5fdcde8dc30fe532.zip |
export interfaces from base in ciphers, update docs
-rw-r--r-- | CHANGELOG.rst | 12 | ||||
-rw-r--r-- | docs/hazmat/backends/interfaces.rst | 18 | ||||
-rw-r--r-- | docs/hazmat/primitives/mac/cmac.rst | 8 | ||||
-rw-r--r-- | docs/hazmat/primitives/symmetric-encryption.rst | 12 | ||||
-rw-r--r-- | src/cryptography/hazmat/backends/commoncrypto/ciphers.py | 12 | ||||
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/ciphers.py | 13 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/ciphers/__init__.py | 10 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/ciphers/algorithms.py | 2 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/cmac.py | 5 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/interfaces/__init__.py | 24 | ||||
-rw-r--r-- | tests/hazmat/backends/test_commoncrypto.py | 2 | ||||
-rw-r--r-- | tests/hazmat/backends/test_openssl.py | 7 |
12 files changed, 66 insertions, 59 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b5c7ef86..8134753a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,13 +14,13 @@ Changelog :class:`~cryptography.hazmat.primitives.hashes.HashContext` were moved from :mod:`~cryptography.hazmat.primitives.interfaces` to :mod:`~cryptography.hazmat.primitives.hashes`. -* :class:`~cryptography.hazmat.primitives.ciphers.base.CipherContext`, - :class:`~cryptography.hazmat.primitives.ciphers.base.AEADCipherContext`, - :class:`~cryptography.hazmat.primitives.ciphers.base.AEADEncryptionContext`, - :class:`~cryptography.hazmat.primitives.ciphers.base.CipherAlgorithm`, and - :class:`~cryptography.hazmat.primitives.ciphers.base.BlockCipherAlgorithm` +* :class:`~cryptography.hazmat.primitives.ciphers.CipherContext`, + :class:`~cryptography.hazmat.primitives.ciphers.AEADCipherContext`, + :class:`~cryptography.hazmat.primitives.ciphers.AEADEncryptionContext`, + :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm`, and + :class:`~cryptography.hazmat.primitives.ciphers.BlockCipherAlgorithm` were moved from :mod:`~cryptography.hazmat.primitives.interfaces` to - :mod:`~cryptography.hazmat.primitives.ciphers.base`. + :mod:`~cryptography.hazmat.primitives.ciphers`. * :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode`, :class:`~cryptography.hazmat.primitives.ciphers.modes.ModeWithInitializationVector`, :class:`~cryptography.hazmat.primitives.ciphers.modes.ModeWithNonce`, and diff --git a/docs/hazmat/backends/interfaces.rst b/docs/hazmat/backends/interfaces.rst index 2f4cdd3b..407140bd 100644 --- a/docs/hazmat/backends/interfaces.rst +++ b/docs/hazmat/backends/interfaces.rst @@ -30,7 +30,7 @@ A specific ``backend`` may provide one or more of these interfaces. this backend. :param cipher: An instance of a - :class:`~cryptography.hazmat.primitives.ciphers.base.CipherAlgorithm` + :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm` provider. :param mode: An instance of a :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode` provider. @@ -42,18 +42,18 @@ A specific ``backend`` may provide one or more of these interfaces. .. method:: create_symmetric_encryption_ctx(cipher, mode) Create a - :class:`~cryptography.hazmat.primitives.ciphers.base.CipherContext` that + :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` that can be used for encrypting data with the symmetric ``cipher`` using the given ``mode``. :param cipher: An instance of a - :class:`~cryptography.hazmat.primitives.ciphers.base.CipherAlgorithm` + :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm` provider. :param mode: An instance of a :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode` provider. :returns: - :class:`~cryptography.hazmat.primitives.ciphers.base.CipherContext` + :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` :raises ValueError: When tag is not None in an AEAD mode @@ -61,18 +61,18 @@ A specific ``backend`` may provide one or more of these interfaces. .. method:: create_symmetric_decryption_ctx(cipher, mode) Create a - :class:`~cryptography.hazmat.primitives.ciphers.base.CipherContext` that + :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` that can be used for decrypting data with the symmetric ``cipher`` using the given ``mode``. :param cipher: An instance of a - :class:`~cryptography.hazmat.primitives.ciphers.base.CipherAlgorithm` + :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm` provider. :param mode: An instance of a :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode` provider. :returns: - :class:`~cryptography.hazmat.primitives.ciphers.base.CipherContext` + :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` :raises ValueError: When tag is None in an AEAD mode @@ -157,7 +157,7 @@ A specific ``backend`` may provide one or more of these interfaces. .. method:: cmac_algorithm_supported(algorithm) :param algorithm: An instance of a - :class:`~cryptography.hazmat.primitives.ciphers.base.BlockCipherAlgorithm` + :class:`~cryptography.hazmat.primitives.ciphers.BlockCipherAlgorithm` provider. :return: Returns True if the block cipher is supported for CMAC by this backend @@ -168,7 +168,7 @@ A specific ``backend`` may provide one or more of these interfaces. uses the specified ``algorithm`` to calculate a message authentication code. :param algorithm: An instance of a - :class:`~cryptography.hazmat.primitives.ciphers.base.BlockCipherAlgorithm` + :class:`~cryptography.hazmat.primitives.ciphers.BlockCipherAlgorithm` provider. :returns: diff --git a/docs/hazmat/primitives/mac/cmac.rst b/docs/hazmat/primitives/mac/cmac.rst index 14e1842f..e04a849f 100644 --- a/docs/hazmat/primitives/mac/cmac.rst +++ b/docs/hazmat/primitives/mac/cmac.rst @@ -22,7 +22,7 @@ A subset of CMAC with the AES-128 algorithm is described in :rfc:`4493`. .. versionadded:: 0.4 CMAC objects take a - :class:`~cryptography.hazmat.primitives.ciphers.base.BlockCipherAlgorithm` provider. + :class:`~cryptography.hazmat.primitives.ciphers.BlockCipherAlgorithm` provider. .. doctest:: @@ -39,7 +39,7 @@ A subset of CMAC with the AES-128 algorithm is described in :rfc:`4493`. raised. If ``algorithm`` isn't a - :class:`~cryptography.hazmat.primitives.ciphers.base.BlockCipherAlgorithm` + :class:`~cryptography.hazmat.primitives.ciphers.BlockCipherAlgorithm` provider then ``TypeError`` will be raised. To check that a given signature is correct use the :meth:`verify` method. @@ -55,13 +55,13 @@ A subset of CMAC with the AES-128 algorithm is described in :rfc:`4493`. cryptography.exceptions.InvalidSignature: Signature did not match digest. :param algorithm: An - :class:`~cryptography.hazmat.primitives.ciphers.base.BlockCipherAlgorithm` + :class:`~cryptography.hazmat.primitives.ciphers.BlockCipherAlgorithm` provider. :param backend: An :class:`~cryptography.hazmat.backends.interfaces.CMACBackend` provider. :raises TypeError: This is raised if the provided ``algorithm`` is not an instance of - :class:`~cryptography.hazmat.primitives.ciphers.base.BlockCipherAlgorithm` + :class:`~cryptography.hazmat.primitives.ciphers.BlockCipherAlgorithm` :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised if the provided ``backend`` does not implement :class:`~cryptography.hazmat.backends.interfaces.CMACBackend` diff --git a/docs/hazmat/primitives/symmetric-encryption.rst b/docs/hazmat/primitives/symmetric-encryption.rst index d47035d8..1cbf60ee 100644 --- a/docs/hazmat/primitives/symmetric-encryption.rst +++ b/docs/hazmat/primitives/symmetric-encryption.rst @@ -4,7 +4,7 @@ Symmetric encryption ==================== -.. currentmodule:: cryptography.hazmat.primitives.ciphers +.. module:: cryptography.hazmat.primitives.ciphers Symmetric encryption is a way to `encrypt`_ or hide the contents of material @@ -43,7 +43,7 @@ in an "encrypt-then-MAC" formulation as `described by Colin Percival`_. 'a secret message' :param algorithms: A - :class:`~cryptography.hazmat.primitives.ciphers.base.CipherAlgorithm` + :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm` provider such as those described :ref:`below <symmetric-encryption-algorithms>`. :param mode: A :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode` @@ -60,7 +60,7 @@ in an "encrypt-then-MAC" formulation as `described by Colin Percival`_. .. method:: encryptor() :return: An encrypting - :class:`~cryptography.hazmat.primitives.ciphers.base.CipherContext` + :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` provider. If the backend doesn't support the requested combination of ``cipher`` @@ -70,7 +70,7 @@ in an "encrypt-then-MAC" formulation as `described by Colin Percival`_. .. method:: decryptor() :return: A decrypting - :class:`~cryptography.hazmat.primitives.ciphers.base.CipherContext` + :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` provider. If the backend doesn't support the requested combination of ``cipher`` @@ -293,7 +293,7 @@ Modes .. danger:: When using this mode you **must** not use the decrypted data until - :meth:`~cryptography.hazmat.primitives.ciphers.base.CipherContext.finalize` + :meth:`~cryptography.hazmat.primitives.ciphers.CipherContext.finalize` has been called. GCM provides **no** guarantees of ciphertext integrity until decryption is complete. @@ -423,7 +423,7 @@ Insecure modes Interfaces ---------- -.. module:: cryptography.hazmat.primitives.ciphers.base +.. currentmodule:: cryptography.hazmat.primitives.ciphers .. class:: CipherContext diff --git a/src/cryptography/hazmat/backends/commoncrypto/ciphers.py b/src/cryptography/hazmat/backends/commoncrypto/ciphers.py index 54715d85..1ce8aec5 100644 --- a/src/cryptography/hazmat/backends/commoncrypto/ciphers.py +++ b/src/cryptography/hazmat/backends/commoncrypto/ciphers.py @@ -8,14 +8,14 @@ from cryptography import utils from cryptography.exceptions import ( InvalidTag, UnsupportedAlgorithm, _Reasons ) -from cryptography.hazmat.primitives import constant_time -from cryptography.hazmat.primitives.ciphers import base, modes +from cryptography.hazmat.primitives import ciphers, constant_time +from cryptography.hazmat.primitives.ciphers import modes from cryptography.hazmat.primitives.ciphers.modes import ( CFB, CFB8, CTR, OFB ) -@utils.register_interface(base.CipherContext) +@utils.register_interface(ciphers.CipherContext) class _CipherContext(object): def __init__(self, backend, cipher, mode, operation): self._backend = backend @@ -32,7 +32,7 @@ class _CipherContext(object): # treat RC4 and other stream cipher block sizes). # This bug has been filed as rdar://15589470 self._bytes_processed = 0 - if (isinstance(cipher, base.BlockCipherAlgorithm) and not + if (isinstance(cipher, ciphers.BlockCipherAlgorithm) and not isinstance(mode, (OFB, CFB, CFB8, CTR))): self._byte_block_size = cipher.block_size // 8 else: @@ -102,8 +102,8 @@ class _CipherContext(object): return self._backend._ffi.buffer(buf)[:outlen[0]] -@utils.register_interface(base.AEADCipherContext) -@utils.register_interface(base.AEADEncryptionContext) +@utils.register_interface(ciphers.AEADCipherContext) +@utils.register_interface(ciphers.AEADEncryptionContext) class _GCMCipherContext(object): def __init__(self, backend, cipher, mode, operation): self._backend = backend diff --git a/src/cryptography/hazmat/backends/openssl/ciphers.py b/src/cryptography/hazmat/backends/openssl/ciphers.py index e836175d..64097c7b 100644 --- a/src/cryptography/hazmat/backends/openssl/ciphers.py +++ b/src/cryptography/hazmat/backends/openssl/ciphers.py @@ -6,12 +6,13 @@ from __future__ import absolute_import, division, print_function from cryptography import utils from cryptography.exceptions import InvalidTag, UnsupportedAlgorithm, _Reasons -from cryptography.hazmat.primitives.ciphers import base, modes +from cryptography.hazmat.primitives import ciphers +from cryptography.hazmat.primitives.ciphers import modes -@utils.register_interface(base.CipherContext) -@utils.register_interface(base.AEADCipherContext) -@utils.register_interface(base.AEADEncryptionContext) +@utils.register_interface(ciphers.CipherContext) +@utils.register_interface(ciphers.AEADCipherContext) +@utils.register_interface(ciphers.AEADEncryptionContext) class _CipherContext(object): _ENCRYPT = 1 _DECRYPT = 0 @@ -23,7 +24,7 @@ class _CipherContext(object): self._operation = operation self._tag = None - if isinstance(self._cipher, base.BlockCipherAlgorithm): + if isinstance(self._cipher, ciphers.BlockCipherAlgorithm): self._block_size = self._cipher.block_size else: self._block_size = 1 @@ -180,7 +181,7 @@ class _CipherContext(object): tag = utils.read_only_property("_tag") -@utils.register_interface(base.CipherContext) +@utils.register_interface(ciphers.CipherContext) class _AESCTRCipherContext(object): """ This is needed to provide support for AES CTR mode in OpenSSL 0.9.8. It can diff --git a/src/cryptography/hazmat/primitives/ciphers/__init__.py b/src/cryptography/hazmat/primitives/ciphers/__init__.py index d779531d..b5dd0ed7 100644 --- a/src/cryptography/hazmat/primitives/ciphers/__init__.py +++ b/src/cryptography/hazmat/primitives/ciphers/__init__.py @@ -4,9 +4,17 @@ from __future__ import absolute_import, division, print_function -from cryptography.hazmat.primitives.ciphers.base import Cipher +from cryptography.hazmat.primitives.ciphers.base import ( + AEADCipherContext, AEADEncryptionContext, BlockCipherAlgorithm, Cipher, + CipherAlgorithm, CipherContext +) __all__ = [ "Cipher", + "CipherAlgorithm", + "BlockCipherAlgorithm", + "CipherContext", + "AEADCipherContext", + "AEADEncryptionContext", ] diff --git a/src/cryptography/hazmat/primitives/ciphers/algorithms.py b/src/cryptography/hazmat/primitives/ciphers/algorithms.py index 0e219bec..b71dddbb 100644 --- a/src/cryptography/hazmat/primitives/ciphers/algorithms.py +++ b/src/cryptography/hazmat/primitives/ciphers/algorithms.py @@ -5,7 +5,7 @@ from __future__ import absolute_import, division, print_function from cryptography import utils -from cryptography.hazmat.primitives.ciphers.base import ( +from cryptography.hazmat.primitives.ciphers import ( BlockCipherAlgorithm, CipherAlgorithm ) diff --git a/src/cryptography/hazmat/primitives/cmac.py b/src/cryptography/hazmat/primitives/cmac.py index d746147a..c2038a30 100644 --- a/src/cryptography/hazmat/primitives/cmac.py +++ b/src/cryptography/hazmat/primitives/cmac.py @@ -9,8 +9,7 @@ from cryptography.exceptions import ( AlreadyFinalized, UnsupportedAlgorithm, _Reasons ) from cryptography.hazmat.backends.interfaces import CMACBackend -from cryptography.hazmat.primitives import interfaces -from cryptography.hazmat.primitives.ciphers import base +from cryptography.hazmat.primitives import ciphers, interfaces @utils.register_interface(interfaces.MACContext) @@ -22,7 +21,7 @@ class CMAC(object): _Reasons.BACKEND_MISSING_INTERFACE ) - if not isinstance(algorithm, base.BlockCipherAlgorithm): + if not isinstance(algorithm, ciphers.BlockCipherAlgorithm): raise TypeError( "Expected instance of BlockCipherAlgorithm." ) diff --git a/src/cryptography/hazmat/primitives/interfaces/__init__.py b/src/cryptography/hazmat/primitives/interfaces/__init__.py index 52433e16..5de7fb8c 100644 --- a/src/cryptography/hazmat/primitives/interfaces/__init__.py +++ b/src/cryptography/hazmat/primitives/interfaces/__init__.py @@ -9,28 +9,28 @@ import abc import six from cryptography import utils -from cryptography.hazmat.primitives import hashes, padding +from cryptography.hazmat.primitives import ciphers, hashes, padding from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa -from cryptography.hazmat.primitives.ciphers import base, modes +from cryptography.hazmat.primitives.ciphers import modes BlockCipherAlgorithm = utils.deprecated( - base.BlockCipherAlgorithm, + ciphers.BlockCipherAlgorithm, __name__, ( "The BlockCipherAlgorithm interface has moved to the " - "cryptography.hazmat.primitives.ciphers.base module" + "cryptography.hazmat.primitives.ciphers module" ), utils.DeprecatedIn08 ) CipherAlgorithm = utils.deprecated( - base.CipherAlgorithm, + ciphers.CipherAlgorithm, __name__, ( "The CipherAlgorithm interface has moved to the " - "cryptography.hazmat.primitives.ciphers.base module" + "cryptography.hazmat.primitives.ciphers module" ), utils.DeprecatedIn08 ) @@ -81,33 +81,33 @@ ModeWithNonce = utils.deprecated( CipherContext = utils.deprecated( - base.CipherContext, + ciphers.CipherContext, __name__, ( "The CipherContext interface has moved to the " - "cryptography.hazmat.primitives.ciphers.base module" + "cryptography.hazmat.primitives.ciphers module" ), utils.DeprecatedIn08 ) AEADCipherContext = utils.deprecated( - base.AEADCipherContext, + ciphers.AEADCipherContext, __name__, ( "The AEADCipherContext interface has moved to the " - "cryptography.hazmat.primitives.ciphers.base module" + "cryptography.hazmat.primitives.ciphers module" ), utils.DeprecatedIn08 ) AEADEncryptionContext = utils.deprecated( - base.AEADEncryptionContext, + ciphers.AEADEncryptionContext, __name__, ( "The AEADEncryptionContext interface has moved to the " - "cryptography.hazmat.primitives.ciphers.base module" + "cryptography.hazmat.primitives.ciphers module" ), utils.DeprecatedIn08 ) diff --git a/tests/hazmat/backends/test_commoncrypto.py b/tests/hazmat/backends/test_commoncrypto.py index c867804e..f7200016 100644 --- a/tests/hazmat/backends/test_commoncrypto.py +++ b/tests/hazmat/backends/test_commoncrypto.py @@ -9,8 +9,8 @@ import pytest from cryptography import utils from cryptography.exceptions import InternalError, _Reasons from cryptography.hazmat.backends import _available_backends +from cryptography.hazmat.primitives.ciphers import Cipher, CipherAlgorithm from cryptography.hazmat.primitives.ciphers.algorithms import AES -from cryptography.hazmat.primitives.ciphers.base import Cipher, CipherAlgorithm from cryptography.hazmat.primitives.ciphers.modes import CBC, GCM from ...utils import raises_unsupported_algorithm diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index 878d71bb..6e3d80e9 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -21,11 +21,10 @@ from cryptography.hazmat.backends.openssl.backend import ( from cryptography.hazmat.backends.openssl.ec import _sn_to_elliptic_curve from cryptography.hazmat.primitives import hashes, interfaces from cryptography.hazmat.primitives.asymmetric import dsa, padding -from cryptography.hazmat.primitives.ciphers import Cipher -from cryptography.hazmat.primitives.ciphers.algorithms import AES -from cryptography.hazmat.primitives.ciphers.base import ( - BlockCipherAlgorithm, CipherAlgorithm +from cryptography.hazmat.primitives.ciphers import ( + BlockCipherAlgorithm, Cipher, CipherAlgorithm ) +from cryptography.hazmat.primitives.ciphers.algorithms import AES from cryptography.hazmat.primitives.ciphers.modes import CBC, CTR, Mode from ..primitives.fixtures_rsa import RSA_KEY_512 |