From f48f69d6654a10a46e34323747c54e0f0ccb7eef Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Sun, 18 Jan 2015 15:57:28 +0000 Subject: Move DSA* interfaces to interfaces.dsa module --- CHANGELOG.rst | 8 + docs/hazmat/backends/interfaces.rst | 12 +- docs/hazmat/primitives/asymmetric/dsa.rst | 177 +++++++++++++++++++-- docs/hazmat/primitives/interfaces.rst | 156 ------------------ .../hazmat/primitives/asymmetric/dsa.py | 86 ++++++++++ .../hazmat/primitives/interfaces/__init__.py | 74 +++++++-- .../hazmat/primitives/interfaces/asymmetric/dsa.py | 93 ----------- src/cryptography/utils.py | 2 + 8 files changed, 332 insertions(+), 276 deletions(-) delete mode 100644 src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py 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)) -- cgit v1.2.3 From d76aa47f9797b9bfa02e1f22b593f1c16a3edc13 Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Sun, 18 Jan 2015 17:15:47 +0000 Subject: Move around bits of the EC test suite to work around awful PyPy bug --- .../hazmat/backends/openssl/backend.py | 12 +++++----- tests/hazmat/backends/test_openssl.py | 26 +++++++++++----------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py index 34efdce9..75d7e32f 100644 --- a/src/cryptography/hazmat/backends/openssl/backend.py +++ b/src/cryptography/hazmat/backends/openssl/backend.py @@ -985,9 +985,6 @@ class Backend(object): "Invalid EC key. Both x and y must be non-negative." ) - bn_x = self._int_to_bn(x) - bn_y = self._int_to_bn(y) - set_func, get_func, group = ( self._ec_key_determine_group_get_set_funcs(ctx) ) @@ -996,6 +993,9 @@ class Backend(object): assert point != self._ffi.NULL point = self._ffi.gc(point, self._lib.EC_POINT_free) + bn_x = self._int_to_bn(x) + bn_y = self._int_to_bn(y) + with self._tmp_bn_ctx() as bn_ctx: check_x = self._lib.BN_CTX_get(bn_ctx) check_y = self._lib.BN_CTX_get(bn_ctx) @@ -1006,8 +1006,10 @@ class Backend(object): res = get_func(group, point, check_x, check_y, bn_ctx) assert res == 1 - assert self._lib.BN_cmp(bn_x, check_x) == 0 - assert self._lib.BN_cmp(bn_y, check_y) == 0 + res = self._lib.BN_cmp(bn_x, check_x) + assert res == 0 + res = self._lib.BN_cmp(bn_y, check_y) + assert res == 0 res = self._lib.EC_KEY_set_public_key(ctx, point) assert res == 1 diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index b6bb5491..5b5c7bd7 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -249,19 +249,6 @@ class TestOpenSSLRandomEngine(object): assert res == 1 assert backend._ffi.buffer(buf)[:] != "\x00" * 500 - def test_activate_osrandom_already_default(self): - e = backend._lib.ENGINE_get_default_RAND() - name = backend._lib.ENGINE_get_name(e) - assert name == backend._lib.Cryptography_osrandom_engine_name - res = backend._lib.ENGINE_free(e) - assert res == 1 - backend.activate_osrandom_engine() - e = backend._lib.ENGINE_get_default_RAND() - name = backend._lib.ENGINE_get_name(e) - assert name == backend._lib.Cryptography_osrandom_engine_name - res = backend._lib.ENGINE_free(e) - assert res == 1 - def test_activate_osrandom_no_default(self): backend.activate_builtin_random() e = backend._lib.ENGINE_get_default_RAND() @@ -292,6 +279,19 @@ class TestOpenSSLRandomEngine(object): e = backend._lib.ENGINE_get_default_RAND() assert e == backend._ffi.NULL + def test_activate_osrandom_already_default(self): + e = backend._lib.ENGINE_get_default_RAND() + name = backend._lib.ENGINE_get_name(e) + assert name == backend._lib.Cryptography_osrandom_engine_name + res = backend._lib.ENGINE_free(e) + assert res == 1 + backend.activate_osrandom_engine() + e = backend._lib.ENGINE_get_default_RAND() + name = backend._lib.ENGINE_get_name(e) + assert name == backend._lib.Cryptography_osrandom_engine_name + res = backend._lib.ENGINE_free(e) + assert res == 1 + class TestOpenSSLRSA(object): def test_generate_rsa_parameters_supported(self): -- cgit v1.2.3