aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2015-01-23 08:25:07 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2015-01-23 08:25:07 -0600
commitb9690abdb3b8afc0599a30deddd06a1681286d47 (patch)
tree7f4b92ddd0c694818718ec28a1e3c6d527ec5cd2 /src
parent418053a577b00a99d45036dc87d711e19d3867e9 (diff)
parentd76aa47f9797b9bfa02e1f22b593f1c16a3edc13 (diff)
downloadcryptography-b9690abdb3b8afc0599a30deddd06a1681286d47.tar.gz
cryptography-b9690abdb3b8afc0599a30deddd06a1681286d47.tar.bz2
cryptography-b9690abdb3b8afc0599a30deddd06a1681286d47.zip
Merge pull request #1634 from public/deprecate-dsa
Move DSA* interfaces to interfaces.dsa module
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/backends/openssl/backend.py12
-rw-r--r--src/cryptography/hazmat/primitives/asymmetric/dsa.py86
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/__init__.py74
-rw-r--r--src/cryptography/hazmat/primitives/interfaces/asymmetric/dsa.py93
-rw-r--r--src/cryptography/utils.py2
5 files changed, 159 insertions, 108 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/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))