diff options
-rw-r--r-- | docs/hazmat/backends/interfaces.rst | 2 | ||||
-rw-r--r-- | docs/hazmat/primitives/asymmetric/rsa.rst | 16 | ||||
-rw-r--r-- | docs/hazmat/primitives/interfaces.rst | 7 | ||||
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/rsa.py | 14 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/asymmetric/padding.py | 19 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/interfaces/__init__.py | 28 | ||||
-rw-r--r-- | tests/hazmat/backends/test_openssl.py | 4 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_rsa.py | 2 |
8 files changed, 54 insertions, 38 deletions
diff --git a/docs/hazmat/backends/interfaces.rst b/docs/hazmat/backends/interfaces.rst index 407140bd..0ce8f5f7 100644 --- a/docs/hazmat/backends/interfaces.rst +++ b/docs/hazmat/backends/interfaces.rst @@ -244,7 +244,7 @@ A specific ``backend`` may provide one or more of these interfaces. Check if the specified ``padding`` is supported by the backend. :param padding: An instance of an - :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricPadding` + :class:`~cryptography.hazmat.primitives.asymmetric.padding.AsymmetricPadding` provider. :returns: ``True`` if the specified ``padding`` is supported by this diff --git a/docs/hazmat/primitives/asymmetric/rsa.rst b/docs/hazmat/primitives/asymmetric/rsa.rst index 4855a45c..19b716e6 100644 --- a/docs/hazmat/primitives/asymmetric/rsa.rst +++ b/docs/hazmat/primitives/asymmetric/rsa.rst @@ -186,7 +186,13 @@ Once you have an encrypted message, it can be decrypted using the private key: Padding ~~~~~~~ -.. currentmodule:: cryptography.hazmat.primitives.asymmetric.padding +.. module:: cryptography.hazmat.primitives.asymmetric.padding + +.. class:: AsymmetricPadding + + .. versionadded:: 0.2 + + .. attribute:: name .. class:: PSS(mgf, salt_length) @@ -425,7 +431,7 @@ Key interfaces Sign data which can be verified later by others using the public key. :param padding: An instance of a - :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricPadding` + :class:`~cryptography.hazmat.primitives.asymmetric.padding.AsymmetricPadding` provider. :param algorithm: An instance of a @@ -444,7 +450,7 @@ Key interfaces :param bytes ciphertext: The ciphertext to decrypt. :param padding: An instance of an - :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricPadding` + :class:`~cryptography.hazmat.primitives.asymmetric.padding.AsymmetricPadding` provider. :return bytes: Decrypted data. @@ -495,7 +501,7 @@ Key interfaces :param bytes signature: The signature to verify. :param padding: An instance of a - :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricPadding` + :class:`~cryptography.hazmat.primitives.asymmetric.padding.AsymmetricPadding` provider. :param algorithm: An instance of a @@ -514,7 +520,7 @@ Key interfaces :param bytes plaintext: The plaintext to encrypt. :param padding: An instance of a - :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricPadding` + :class:`~cryptography.hazmat.primitives.asymmetric.padding.AsymmetricPadding` provider. :return bytes: Encrypted data. diff --git a/docs/hazmat/primitives/interfaces.rst b/docs/hazmat/primitives/interfaces.rst index 67c6b3d5..2d403525 100644 --- a/docs/hazmat/primitives/interfaces.rst +++ b/docs/hazmat/primitives/interfaces.rst @@ -44,11 +44,8 @@ Asymmetric interfaces not validate. -.. class:: AsymmetricPadding - - .. versionadded:: 0.2 - - .. attribute:: name +In 0.8 the asymmetric padding interface was moved to the +:mod:`cryptography.hazmat.primitives.asymmetric.padding` module. DSA ~~~ diff --git a/src/cryptography/hazmat/backends/openssl/rsa.py b/src/cryptography/hazmat/backends/openssl/rsa.py index 310b9949..a4bb283d 100644 --- a/src/cryptography/hazmat/backends/openssl/rsa.py +++ b/src/cryptography/hazmat/backends/openssl/rsa.py @@ -13,7 +13,7 @@ from cryptography.exceptions import ( from cryptography.hazmat.primitives import hashes, interfaces from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric.padding import ( - MGF1, OAEP, PKCS1v15, PSS + AsymmetricPadding, MGF1, OAEP, PKCS1v15, PSS ) from cryptography.hazmat.primitives.interfaces import ( RSAPrivateKeyWithNumbers, RSAPublicKeyWithNumbers @@ -34,7 +34,7 @@ def _get_rsa_pss_salt_length(pss, key_size, digest_size): def _enc_dec_rsa(backend, key, data, padding): - if not isinstance(padding, interfaces.AsymmetricPadding): + if not isinstance(padding, AsymmetricPadding): raise TypeError("Padding must be an instance of AsymmetricPadding.") if isinstance(padding, PKCS1v15): @@ -150,9 +150,8 @@ class _RSASignatureContext(object): self._backend = backend self._private_key = private_key - if not isinstance(padding, interfaces.AsymmetricPadding): - raise TypeError( - "Expected provider of interfaces.AsymmetricPadding.") + if not isinstance(padding, AsymmetricPadding): + raise TypeError("Expected provider of AsymmetricPadding.") self._pkey_size = self._backend._lib.EVP_PKEY_size( self._private_key._evp_pkey @@ -339,9 +338,8 @@ class _RSAVerificationContext(object): self._public_key = public_key self._signature = signature - if not isinstance(padding, interfaces.AsymmetricPadding): - raise TypeError( - "Expected provider of interfaces.AsymmetricPadding.") + if not isinstance(padding, AsymmetricPadding): + raise TypeError("Expected provider of AsymmetricPadding.") self._pkey_size = self._backend._lib.EVP_PKEY_size( self._public_key._evp_pkey diff --git a/src/cryptography/hazmat/primitives/asymmetric/padding.py b/src/cryptography/hazmat/primitives/asymmetric/padding.py index d0c3eade..c796d8e4 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/padding.py +++ b/src/cryptography/hazmat/primitives/asymmetric/padding.py @@ -4,18 +4,29 @@ from __future__ import absolute_import, division, print_function +import abc + import six from cryptography import utils -from cryptography.hazmat.primitives import hashes, interfaces +from cryptography.hazmat.primitives import hashes + + +@six.add_metaclass(abc.ABCMeta) +class AsymmetricPadding(object): + @abc.abstractproperty + def name(self): + """ + A string naming this padding (e.g. "PSS", "PKCS1"). + """ -@utils.register_interface(interfaces.AsymmetricPadding) +@utils.register_interface(AsymmetricPadding) class PKCS1v15(object): name = "EMSA-PKCS1-v1_5" -@utils.register_interface(interfaces.AsymmetricPadding) +@utils.register_interface(AsymmetricPadding) class PSS(object): MAX_LENGTH = object() name = "EMSA-PSS" @@ -33,7 +44,7 @@ class PSS(object): self._salt_length = salt_length -@utils.register_interface(interfaces.AsymmetricPadding) +@utils.register_interface(AsymmetricPadding) class OAEP(object): name = "EME-OAEP" diff --git a/src/cryptography/hazmat/primitives/interfaces/__init__.py b/src/cryptography/hazmat/primitives/interfaces/__init__.py index 5de7fb8c..75426aa8 100644 --- a/src/cryptography/hazmat/primitives/interfaces/__init__.py +++ b/src/cryptography/hazmat/primitives/interfaces/__init__.py @@ -9,9 +9,12 @@ import abc import six from cryptography import utils -from cryptography.hazmat.primitives import ciphers, hashes, padding -from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa +from cryptography.hazmat.primitives import ciphers, hashes +from cryptography.hazmat.primitives.asymmetric import ( + dsa, ec, padding, rsa +) from cryptography.hazmat.primitives.ciphers import modes +from cryptography.hazmat.primitives.padding import PaddingContext BlockCipherAlgorithm = utils.deprecated( @@ -241,7 +244,7 @@ DSAPublicKeyWithNumbers = utils.deprecated( PaddingContext = utils.deprecated( - padding.PaddingContext, + PaddingContext, __name__, ( "The PaddingContext interface has moved to the " @@ -313,6 +316,16 @@ RSAPublicKeyWithNumbers = utils.deprecated( utils.DeprecatedIn08 ) +AsymmetricPadding = utils.deprecated( + padding.AsymmetricPadding, + __name__, + ( + "The AsymmetricPadding interface has moved to the " + "cryptography.hazmat.primitives.asymmetric.padding module" + ), + utils.DeprecatedIn08 +) + @six.add_metaclass(abc.ABCMeta) class AsymmetricSignatureContext(object): @@ -346,15 +359,6 @@ class AsymmetricVerificationContext(object): @six.add_metaclass(abc.ABCMeta) -class AsymmetricPadding(object): - @abc.abstractproperty - def name(self): - """ - A string naming this padding (e.g. "PSS", "PKCS1"). - """ - - -@six.add_metaclass(abc.ABCMeta) class KeyDerivationFunction(object): @abc.abstractmethod def derive(self, key_material): diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index 6e3d80e9..21e902f1 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -19,7 +19,7 @@ from cryptography.hazmat.backends.openssl.backend import ( Backend, backend ) from cryptography.hazmat.backends.openssl.ec import _sn_to_elliptic_curve -from cryptography.hazmat.primitives import hashes, interfaces +from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import dsa, padding from cryptography.hazmat.primitives.ciphers import ( BlockCipherAlgorithm, Cipher, CipherAlgorithm @@ -45,7 +45,7 @@ class DummyCipher(object): key_size = None -@utils.register_interface(interfaces.AsymmetricPadding) +@utils.register_interface(padding.AsymmetricPadding) class DummyPadding(object): name = "dummy-cipher" diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index 33e5373b..6d8e6874 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -37,7 +37,7 @@ from ...utils import ( ) -@utils.register_interface(interfaces.AsymmetricPadding) +@utils.register_interface(padding.AsymmetricPadding) class DummyPadding(object): name = "UNSUPPORTED-PADDING" |