diff options
-rw-r--r-- | CHANGELOG.rst | 16 | ||||
-rw-r--r-- | docs/hazmat/primitives/padding.rst | 6 | ||||
-rw-r--r-- | docs/hazmat/primitives/symmetric-encryption.rst | 12 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/interfaces/__init__.py | 24 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/padding.py | 22 |
5 files changed, 59 insertions, 21 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a42a4d18..b5c7ef86 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,22 @@ 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` + were moved from :mod:`~cryptography.hazmat.primitives.interfaces` to + :mod:`~cryptography.hazmat.primitives.ciphers.base`. +* :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode`, + :class:`~cryptography.hazmat.primitives.ciphers.modes.ModeWithInitializationVector`, + :class:`~cryptography.hazmat.primitives.ciphers.modes.ModeWithNonce`, and + :class:`~cryptography.hazmat.primitives.ciphers.modes.ModeWithAuthenticationTag` + were moved from :mod:`~cryptography.hazmat.primitives.interfaces` to + :mod:`~cryptography.hazmat.primitives.ciphers.modes`. +* :class:`~cryptography.hazmat.primitives.padding.PaddingContext` was moved + from :mod:`~cryptography.hazmat.primitives.interfaces` to + :mod:`~cryptography.hazmat.primitives.padding`. * :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters`, :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParametersWithNumbers`, :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`, diff --git a/docs/hazmat/primitives/padding.rst b/docs/hazmat/primitives/padding.rst index 0322f9d2..203eb5bc 100644 --- a/docs/hazmat/primitives/padding.rst +++ b/docs/hazmat/primitives/padding.rst @@ -44,18 +44,16 @@ multiple of the block size. .. method:: padder() :returns: A padding - :class:`~cryptography.hazmat.primitives.interfaces.PaddingContext` + :class:`~cryptography.hazmat.primitives.padding.PaddingContext` provider. .. method:: unpadder() :returns: An unpadding - :class:`~cryptography.hazmat.primitives.interfaces.PaddingContext` + :class:`~cryptography.hazmat.primitives.padding.PaddingContext` provider. -.. currentmodule:: cryptography.hazmat.primitives.interfaces - .. class:: PaddingContext When calling ``padder()`` or ``unpadder()`` the result will conform to the diff --git a/docs/hazmat/primitives/symmetric-encryption.rst b/docs/hazmat/primitives/symmetric-encryption.rst index 53023015..0692f0f2 100644 --- a/docs/hazmat/primitives/symmetric-encryption.rst +++ b/docs/hazmat/primitives/symmetric-encryption.rst @@ -591,6 +591,18 @@ Interfaces used by the symmetric cipher modes described in individual modes. +.. class:: ModeWithAuthenticationTag + + A cipher mode with an authentication tag. + + .. attribute:: tag + + :type: bytes + + Exact requirements of the tag are described by the documentation of + individual modes. + + .. _`described by Colin Percival`: http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html .. _`recommends a 96-bit IV length`: http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-spec.pdf diff --git a/src/cryptography/hazmat/primitives/interfaces/__init__.py b/src/cryptography/hazmat/primitives/interfaces/__init__.py index e9ba7808..52433e16 100644 --- a/src/cryptography/hazmat/primitives/interfaces/__init__.py +++ b/src/cryptography/hazmat/primitives/interfaces/__init__.py @@ -9,7 +9,7 @@ import abc import six from cryptography import utils -from cryptography.hazmat.primitives import hashes +from cryptography.hazmat.primitives import hashes, padding from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa from cryptography.hazmat.primitives.ciphers import base, modes @@ -240,19 +240,15 @@ DSAPublicKeyWithNumbers = utils.deprecated( ) -@six.add_metaclass(abc.ABCMeta) -class PaddingContext(object): - @abc.abstractmethod - def update(self, data): - """ - Pads the provided bytes and returns any available data as bytes. - """ - - @abc.abstractmethod - def finalize(self): - """ - Finalize the padding, returns bytes. - """ +PaddingContext = utils.deprecated( + padding.PaddingContext, + __name__, + ( + "The PaddingContext interface has moved to the " + "cryptography.hazmat.primitives.padding module" + ), + utils.DeprecatedIn08 +) HashContext = utils.deprecated( diff --git a/src/cryptography/hazmat/primitives/padding.py b/src/cryptography/hazmat/primitives/padding.py index 49cae9d6..8ad64dec 100644 --- a/src/cryptography/hazmat/primitives/padding.py +++ b/src/cryptography/hazmat/primitives/padding.py @@ -4,12 +4,13 @@ from __future__ import absolute_import, division, print_function +import abc + import six from cryptography import utils from cryptography.exceptions import AlreadyFinalized from cryptography.hazmat.bindings.utils import LazyLibrary, build_ffi -from cryptography.hazmat.primitives import interfaces TYPES = """ @@ -59,6 +60,21 @@ _ffi = build_ffi(cdef_source=TYPES, verify_source=FUNCTIONS) _lib = LazyLibrary(_ffi) +@six.add_metaclass(abc.ABCMeta) +class PaddingContext(object): + @abc.abstractmethod + def update(self, data): + """ + Pads the provided bytes and returns any available data as bytes. + """ + + @abc.abstractmethod + def finalize(self): + """ + Finalize the padding, returns bytes. + """ + + class PKCS7(object): def __init__(self, block_size): if not (0 <= block_size < 256): @@ -76,7 +92,7 @@ class PKCS7(object): return _PKCS7UnpaddingContext(self.block_size) -@utils.register_interface(interfaces.PaddingContext) +@utils.register_interface(PaddingContext) class _PKCS7PaddingContext(object): def __init__(self, block_size): self.block_size = block_size @@ -109,7 +125,7 @@ class _PKCS7PaddingContext(object): return result -@utils.register_interface(interfaces.PaddingContext) +@utils.register_interface(PaddingContext) class _PKCS7UnpaddingContext(object): def __init__(self, block_size): self.block_size = block_size |