diff options
-rw-r--r-- | CHANGELOG.rst | 8 | ||||
-rw-r--r-- | docs/hazmat/backends/interfaces.rst | 12 | ||||
-rw-r--r-- | docs/hazmat/primitives/asymmetric/dsa.rst | 177 | ||||
-rw-r--r-- | docs/hazmat/primitives/interfaces.rst | 156 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/asymmetric/dsa.py | 86 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/interfaces/__init__.py | 74 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py | 93 | ||||
-rw-r--r-- | src/cryptography/utils.py | 2 |
8 files changed, 332 insertions, 276 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5944b907..64a15f1f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,14 @@ Changelog now load elliptic curve public keys. * Added :func:`~cryptography.hazmat.primitives.asymmetric.rsa.rsa_recover_prime_factors` +* :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters`, + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParametersWithNumbers`, + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`, + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKeyWithNumbers`, + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` and + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKeyWithNumbers` + were moved from :mod:`~cryptography.hazmat.primitives.interfaces` to + :mod:`~cryptography.hazmat.primitives.asymmetric.dsa` 0.7.2 - 2015-01-16 ~~~~~~~~~~~~~~~~~~ diff --git a/docs/hazmat/backends/interfaces.rst b/docs/hazmat/backends/interfaces.rst index 8efe2ce9..9afbcb67 100644 --- a/docs/hazmat/backends/interfaces.rst +++ b/docs/hazmat/backends/interfaces.rst @@ -306,17 +306,17 @@ A specific ``backend`` may provide one or more of these interfaces. restricted to only the 1024-bit keys specified in FIPS 186-2. :return: A new instance of a - :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters` + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters` provider. .. method:: generate_dsa_private_key(parameters) :param parameters: A - :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters` + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters` provider. :return: A new instance of a - :class:`~cryptography.hazmat.primitives.interfaces.DSAPrivateKey` + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` provider. :raises ValueError: This is raised if the key size is not one of 1024, @@ -366,7 +366,7 @@ A specific ``backend`` may provide one or more of these interfaces. :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameterNumbers`. :returns: A provider of - :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters`. + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters`. :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised when any backend specific criteria are not met. @@ -377,7 +377,7 @@ A specific ``backend`` may provide one or more of these interfaces. :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateNumbers`. :returns: A provider of - :class:`~cryptography.hazmat.primitives.interfaces.DSAPrivateKey`. + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`. :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised when any backend specific criteria are not met. @@ -388,7 +388,7 @@ A specific ``backend`` may provide one or more of these interfaces. :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicNumbers`. :returns: A provider of - :class:`~cryptography.hazmat.primitives.interfaces.DSAPublicKey`. + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`. :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised when any backend specific criteria are not met. diff --git a/docs/hazmat/primitives/asymmetric/dsa.rst b/docs/hazmat/primitives/asymmetric/dsa.rst index c2197d10..ff934a6a 100644 --- a/docs/hazmat/primitives/asymmetric/dsa.rst +++ b/docs/hazmat/primitives/asymmetric/dsa.rst @@ -28,7 +28,7 @@ Generation :class:`~cryptography.hazmat.backends.interfaces.DSABackend` provider. - :return: A :class:`~cryptography.hazmat.primitives.interfaces.DSAPrivateKey` + :return: A :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` provider. :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised if @@ -52,7 +52,7 @@ Generation :class:`~cryptography.hazmat.backends.interfaces.DSABackend` provider. - :return: A :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters` + :return: A :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters` provider. :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised if @@ -62,7 +62,7 @@ Generation Signing ~~~~~~~ -Using a :class:`~cryptography.hazmat.primitives.interfaces.DSAPrivateKey` +Using a :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` provider. .. doctest:: @@ -86,7 +86,7 @@ described in :rfc:`6979`. This can be decoded using Verification ~~~~~~~~~~~~ -Using a :class:`~cryptography.hazmat.primitives.interfaces.DSAPublicKey` +Using a :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` provider. .. doctest:: @@ -136,7 +136,7 @@ Numbers provider. :returns: A new instance of a - :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters` + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters` provider. .. class:: DSAPublicNumbers(y, parameter_numbers) @@ -153,9 +153,9 @@ Numbers .. attribute:: parameter_numbers - :type: :class:`~cryptography.hazmat.primitives.dsa.DSAParameterNumbers` + :type: :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameterNumbers` - The :class:`~cryptography.hazmat.primitives.dsa.DSAParameterNumbers` + The :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameterNumbers` associated with the public key. .. method:: public_key(backend) @@ -165,7 +165,7 @@ Numbers provider. :returns: A new instance of a - :class:`~cryptography.hazmat.primitives.interfaces.DSAPublicKey` + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` provider. .. class:: DSAPrivateNumbers(x, public_numbers) @@ -187,9 +187,9 @@ Numbers .. attribute:: public_numbers - :type: :class:`~cryptography.hazmat.primitives.dsa.DSAPublicNumbers` + :type: :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicNumbers` - The :class:`~cryptography.hazmat.primitives.dsa.DSAPublicNumbers` + The :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicNumbers` associated with the private key. .. method:: private_key(backend) @@ -199,9 +199,164 @@ Numbers provider. :returns: A new instance of a - :class:`~cryptography.hazmat.primitives.interfaces.DSAPrivateKey` + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` provider. +Key interfaces +~~~~~~~~~~~~~~ + +.. class:: DSAParameters + + .. versionadded:: 0.3 + + `DSA`_ parameters. + + .. method:: generate_private_key() + + .. versionadded:: 0.5 + + Generate a DSA private key. This method can be used to generate many + new private keys from a single set of parameters. + + :return: A + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` + provider. + + +.. class:: DSAParametersWithNumbers + + .. versionadded:: 0.5 + + Extends :class:`DSAParameters`. + + .. method:: parameter_numbers() + + Create a + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameterNumbers` + object. + + :returns: A + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameterNumbers` + instance. + + +.. class:: DSAPrivateKey + + .. versionadded:: 0.3 + + A `DSA`_ private key. + + .. method:: public_key() + + :return: :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` + + An DSA public key object corresponding to the values of the private key. + + .. method:: parameters() + + :return: :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters` + + The DSAParameters object associated with this private key. + + .. method:: signer(algorithm, backend) + + .. versionadded:: 0.4 + + Sign data which can be verified later by others using the public key. + The signature is formatted as DER-encoded bytes, as specified in + :rfc:`6979`. + + :param algorithm: An instance of a + :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` + provider. + + :param backend: A + :class:`~cryptography.hazmat.backends.interfaces.DSABackend` + provider. + + :returns: + :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricSignatureContext` + + .. attribute:: key_size + + :type: int + + The bit length of the modulus. + + +.. class:: DSAPrivateKeyWithNumbers + + .. versionadded:: 0.5 + + Extends :class:`DSAPrivateKey`. + + .. method:: private_numbers() + + Create a + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateNumbers` + object. + + :returns: A + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateNumbers` + instance. + + +.. class:: DSAPublicKey + + .. versionadded:: 0.3 + + A `DSA`_ public key. + + .. attribute:: key_size + + :type: int + + The bit length of the modulus. + + .. method:: parameters() + + :return: :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters` + + The DSAParameters object associated with this public key. + + .. method:: verifier(signature, algorithm, backend) + + .. versionadded:: 0.4 + + Verify data was signed by the private key associated with this public + key. + + :param bytes signature: The signature to verify. DER encoded as + specified in :rfc:`6979`. + + :param algorithm: An instance of a + :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` + provider. + + :param backend: A + :class:`~cryptography.hazmat.backends.interfaces.DSABackend` + provider. + + :returns: + :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricVerificationContext` + + +.. class:: DSAPublicKeyWithNumbers + + .. versionadded:: 0.5 + + Extends :class:`DSAPublicKey`. + + .. method:: public_numbers() + + Create a + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicNumbers` + object. + + :returns: A + :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicNumbers` + instance. + .. _`DSA`: https://en.wikipedia.org/wiki/Digital_Signature_Algorithm .. _`public-key`: https://en.wikipedia.org/wiki/Public-key_cryptography diff --git a/docs/hazmat/primitives/interfaces.rst b/docs/hazmat/primitives/interfaces.rst index 2dea46d2..2ba140bd 100644 --- a/docs/hazmat/primitives/interfaces.rst +++ b/docs/hazmat/primitives/interfaces.rst @@ -273,162 +273,6 @@ RSA instance. -DSA -~~~ - -.. class:: DSAParameters - - .. versionadded:: 0.3 - - `DSA`_ parameters. - - .. method:: generate_private_key() - - .. versionadded:: 0.5 - - Generate a DSA private key. This method can be used to generate many - new private keys from a single set of parameters. - - :return: A - :class:`~cryptography.hazmat.primitives.interfaces.DSAPrivateKey` - provider. - - -.. class:: DSAParametersWithNumbers - - .. versionadded:: 0.5 - - Extends :class:`DSAParameters`. - - .. method:: parameter_numbers() - - Create a - :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameterNumbers` - object. - - :returns: A - :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameterNumbers` - instance. - - -.. class:: DSAPrivateKey - - .. versionadded:: 0.3 - - A `DSA`_ private key. - - .. method:: public_key() - - :return: :class:`~cryptography.hazmat.primitives.interfaces.DSAPublicKey` - - An DSA public key object corresponding to the values of the private key. - - .. method:: parameters() - - :return: :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters` - - The DSAParameters object associated with this private key. - - .. method:: signer(algorithm, backend) - - .. versionadded:: 0.4 - - Sign data which can be verified later by others using the public key. - The signature is formatted as DER-encoded bytes, as specified in - :rfc:`6979`. - - :param algorithm: An instance of a - :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` - provider. - - :param backend: A - :class:`~cryptography.hazmat.backends.interfaces.DSABackend` - provider. - - :returns: - :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricSignatureContext` - - .. attribute:: key_size - - :type: int - - The bit length of the modulus. - - -.. class:: DSAPrivateKeyWithNumbers - - .. versionadded:: 0.5 - - Extends :class:`DSAPrivateKey`. - - .. method:: private_numbers() - - Create a - :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateNumbers` - object. - - :returns: A - :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateNumbers` - instance. - - -.. class:: DSAPublicKey - - .. versionadded:: 0.3 - - A `DSA`_ public key. - - .. attribute:: key_size - - :type: int - - The bit length of the modulus. - - .. method:: parameters() - - :return: :class:`~cryptography.hazmat.primitives.interfaces.DSAParameters` - - The DSAParameters object associated with this public key. - - .. method:: verifier(signature, algorithm, backend) - - .. versionadded:: 0.4 - - Verify data was signed by the private key associated with this public - key. - - :param bytes signature: The signature to verify. DER encoded as - specified in :rfc:`6979`. - - :param algorithm: An instance of a - :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` - provider. - - :param backend: A - :class:`~cryptography.hazmat.backends.interfaces.DSABackend` - provider. - - :returns: - :class:`~cryptography.hazmat.primitives.interfaces.AsymmetricVerificationContext` - - -.. class:: DSAPublicKeyWithNumbers - - .. versionadded:: 0.5 - - Extends :class:`DSAPublicKey`. - - .. method:: public_numbers() - - Create a - :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicNumbers` - object. - - :returns: A - :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicNumbers` - instance. - - .. class:: EllipticCurve .. versionadded:: 0.5 diff --git a/src/cryptography/hazmat/primitives/asymmetric/dsa.py b/src/cryptography/hazmat/primitives/asymmetric/dsa.py index 9b06f3e6..58058df9 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/dsa.py +++ b/src/cryptography/hazmat/primitives/asymmetric/dsa.py @@ -4,11 +4,97 @@ from __future__ import absolute_import, division, print_function +import abc + import six from cryptography import utils +@six.add_metaclass(abc.ABCMeta) +class DSAParameters(object): + @abc.abstractmethod + def generate_private_key(self): + """ + Generates and returns a DSAPrivateKey. + """ + + +@six.add_metaclass(abc.ABCMeta) +class DSAParametersWithNumbers(DSAParameters): + @abc.abstractmethod + def parameter_numbers(self): + """ + Returns a DSAParameterNumbers. + """ + + +@six.add_metaclass(abc.ABCMeta) +class DSAPrivateKey(object): + @abc.abstractproperty + def key_size(self): + """ + The bit length of the prime modulus. + """ + + @abc.abstractmethod + def public_key(self): + """ + The DSAPublicKey associated with this private key. + """ + + @abc.abstractmethod + def parameters(self): + """ + The DSAParameters object associated with this private key. + """ + + @abc.abstractmethod + def signer(self, signature_algorithm): + """ + Returns an AsymmetricSignatureContext used for signing data. + """ + + +@six.add_metaclass(abc.ABCMeta) +class DSAPrivateKeyWithNumbers(DSAPrivateKey): + @abc.abstractmethod + def private_numbers(self): + """ + Returns a DSAPrivateNumbers. + """ + + +@six.add_metaclass(abc.ABCMeta) +class DSAPublicKey(object): + @abc.abstractproperty + def key_size(self): + """ + The bit length of the prime modulus. + """ + + @abc.abstractmethod + def parameters(self): + """ + The DSAParameters object associated with this public key. + """ + + @abc.abstractmethod + def verifier(self, signature, signature_algorithm): + """ + Returns an AsymmetricVerificationContext used for signing data. + """ + + +@six.add_metaclass(abc.ABCMeta) +class DSAPublicKeyWithNumbers(DSAPublicKey): + @abc.abstractmethod + def public_numbers(self): + """ + Returns a DSAPublicNumbers. + """ + + def generate_parameters(key_size, backend): return backend.generate_dsa_parameters(key_size) diff --git a/src/cryptography/hazmat/primitives/interfaces/__init__.py b/src/cryptography/hazmat/primitives/interfaces/__init__.py index fb5ceeae..7961cf15 100644 --- a/src/cryptography/hazmat/primitives/interfaces/__init__.py +++ b/src/cryptography/hazmat/primitives/interfaces/__init__.py @@ -8,10 +8,10 @@ import abc import six -from cryptography.hazmat.primitives.interfaces.asymmetric.dsa import ( - DSAParameters, DSAParametersWithNumbers, DSAPrivateKey, - DSAPrivateKeyWithNumbers, DSAPublicKey, DSAPublicKeyWithNumbers -) +from cryptography import utils + +from cryptography.hazmat.primitives.asymmetric import dsa + from cryptography.hazmat.primitives.interfaces.asymmetric.ec import ( EllipticCurve, EllipticCurvePrivateKey, EllipticCurvePrivateKeyWithNumbers, EllipticCurvePublicKey, EllipticCurvePublicKeyWithNumbers, @@ -25,12 +25,6 @@ from cryptography.hazmat.primitives.interfaces.ciphers import ( __all__ = [ "BlockCipherAlgorithm", "CipherAlgorithm", - "DSAParameters", - "DSAParametersWithNumbers", - "DSAPrivateKey", - "DSAPrivateKeyWithNumbers", - "DSAPublicKey", - "DSAPublicKeyWithNumbers", "EllipticCurve", "EllipticCurvePrivateKey", "EllipticCurvePrivateKeyWithNumbers", @@ -43,6 +37,66 @@ __all__ = [ "ModeWithNonce" ] +DSAParameters = utils.deprecated( + dsa.DSAParameters, + __name__, + ( + "The DSAParameters interface has moved to the " + "cryptography.hazmat.primitives.asymmetric.dsa.module" + ), + utils.DeprecatedIn08 +) + +DSAParametersWithNumbers = utils.deprecated( + dsa.DSAParametersWithNumbers, + __name__, + ( + "The DSAParametersWithNumbers interface has moved to the " + "cryptography.hazmat.primitives.asymmetric.dsa.module" + ), + utils.DeprecatedIn08 +) + +DSAPrivateKey = utils.deprecated( + dsa.DSAPrivateKey, + __name__, + ( + "The DSAPrivateKey interface has moved to the " + "cryptography.hazmat.primitives.asymmetric.dsa.module" + ), + utils.DeprecatedIn08 +) + +DSAPrivateKeyWithNumbers = utils.deprecated( + dsa.DSAPrivateKeyWithNumbers, + __name__, + ( + "The DSAPrivateKeyWithNumbers interface has moved to the " + "cryptography.hazmat.primitives.asymmetric.dsa.module" + ), + utils.DeprecatedIn08 +) + +DSAPublicKey = utils.deprecated( + dsa.DSAPublicKey, + __name__, + ( + "The DSAPublicKeyWithNumbers interface has moved to the " + "cryptography.hazmat.primitives.asymmetric.dsa.module" + ), + utils.DeprecatedIn08 +) + +DSAPublicKeyWithNumbers = utils.deprecated( + dsa.DSAPublicKeyWithNumbers, + __name__, + ( + "The DSAPublicKeyWithNumbers interface has moved to the " + "cryptography.hazmat.primitives.asymmetric.dsa.module" + ), + utils.DeprecatedIn08 +) + @six.add_metaclass(abc.ABCMeta) class CipherContext(object): diff --git a/src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py b/src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py deleted file mode 100644 index acfc8973..00000000 --- a/src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py +++ /dev/null @@ -1,93 +0,0 @@ -# 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 DSAParameters(object): - @abc.abstractmethod - def generate_private_key(self): - """ - Generates and returns a DSAPrivateKey. - """ - - -@six.add_metaclass(abc.ABCMeta) -class DSAParametersWithNumbers(DSAParameters): - @abc.abstractmethod - def parameter_numbers(self): - """ - Returns a DSAParameterNumbers. - """ - - -@six.add_metaclass(abc.ABCMeta) -class DSAPrivateKey(object): - @abc.abstractproperty - def key_size(self): - """ - The bit length of the prime modulus. - """ - - @abc.abstractmethod - def public_key(self): - """ - The DSAPublicKey associated with this private key. - """ - - @abc.abstractmethod - def parameters(self): - """ - The DSAParameters object associated with this private key. - """ - - @abc.abstractmethod - def signer(self, signature_algorithm): - """ - Returns an AsymmetricSignatureContext used for signing data. - """ - - -@six.add_metaclass(abc.ABCMeta) -class DSAPrivateKeyWithNumbers(DSAPrivateKey): - @abc.abstractmethod - def private_numbers(self): - """ - Returns a DSAPrivateNumbers. - """ - - -@six.add_metaclass(abc.ABCMeta) -class DSAPublicKey(object): - @abc.abstractproperty - def key_size(self): - """ - The bit length of the prime modulus. - """ - - @abc.abstractmethod - def parameters(self): - """ - The DSAParameters object associated with this public key. - """ - - @abc.abstractmethod - def verifier(self, signature, signature_algorithm): - """ - Returns an AsymmetricVerificationContext used for signing data. - """ - - -@six.add_metaclass(abc.ABCMeta) -class DSAPublicKeyWithNumbers(DSAPublicKey): - @abc.abstractmethod - def public_numbers(self): - """ - Returns a DSAPublicNumbers. - """ diff --git a/src/cryptography/utils.py b/src/cryptography/utils.py index 72f9a347..78dcc1ca 100644 --- a/src/cryptography/utils.py +++ b/src/cryptography/utils.py @@ -13,6 +13,8 @@ import warnings # DeprecatedIn07 objects exist. This comment exists to remind developers to # look for them when it's time for the ninth release cycle deprecation dance. +DeprecatedIn08 = PendingDeprecationWarning + def read_only_property(name): return property(lambda self: getattr(self, name)) |