diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2014-09-27 11:59:56 -0400 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2014-09-27 11:59:56 -0400 |
commit | e9022fee01112d00d97ebc499a48f5d71fb83af7 (patch) | |
tree | 8645894150322408d44d200c6e303fa20e868f99 /cryptography | |
parent | 45d4c5909bd857986b901d59fd4d77bce63bfeff (diff) | |
parent | cff58d8d28ad15a8f7abaaa6ff5320a7d1f5b2f9 (diff) | |
download | cryptography-e9022fee01112d00d97ebc499a48f5d71fb83af7.tar.gz cryptography-e9022fee01112d00d97ebc499a48f5d71fb83af7.tar.bz2 cryptography-e9022fee01112d00d97ebc499a48f5d71fb83af7.zip |
Merge pull request #1348 from reaperhulk/improve-naming-consistency
deprecate backend method names for elliptic curve number loading
Diffstat (limited to 'cryptography')
-rw-r--r-- | cryptography/hazmat/backends/interfaces.py | 4 | ||||
-rw-r--r-- | cryptography/hazmat/backends/multibackend.py | 38 | ||||
-rw-r--r-- | cryptography/hazmat/backends/openssl/backend.py | 18 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/asymmetric/ec.py | 10 |
4 files changed, 66 insertions, 4 deletions
diff --git a/cryptography/hazmat/backends/interfaces.py b/cryptography/hazmat/backends/interfaces.py index dc720ad3..f471b948 100644 --- a/cryptography/hazmat/backends/interfaces.py +++ b/cryptography/hazmat/backends/interfaces.py @@ -260,13 +260,13 @@ class EllipticCurveBackend(object): """ @abc.abstractmethod - def elliptic_curve_public_key_from_numbers(self, numbers): + def load_elliptic_curve_public_numbers(self, numbers): """ Return an EllipticCurvePublicKey provider using the given numbers. """ @abc.abstractmethod - def elliptic_curve_private_key_from_numbers(self, numbers): + def load_elliptic_curve_private_numbers(self, numbers): """ Return an EllipticCurvePublicKey provider using the given numbers. """ diff --git a/cryptography/hazmat/backends/multibackend.py b/cryptography/hazmat/backends/multibackend.py index 163dd0ee..ce9e6dee 100644 --- a/cryptography/hazmat/backends/multibackend.py +++ b/cryptography/hazmat/backends/multibackend.py @@ -13,6 +13,8 @@ from __future__ import absolute_import, division, print_function +import warnings + from cryptography import utils from cryptography.exceptions import UnsupportedAlgorithm, _Reasons from cryptography.hazmat.backends.interfaces import ( @@ -297,6 +299,12 @@ class MultiBackend(object): ) def elliptic_curve_private_key_from_numbers(self, numbers): + warnings.warn( + "elliptic_curve_private_key_from_numbers is deprecated and will " + "be removed in a future version.", + utils.DeprecatedIn06, + stacklevel=2 + ) for b in self._filtered_backends(EllipticCurveBackend): try: return b.elliptic_curve_private_key_from_numbers(numbers) @@ -308,7 +316,25 @@ class MultiBackend(object): _Reasons.UNSUPPORTED_ELLIPTIC_CURVE ) + def load_elliptic_curve_private_numbers(self, numbers): + for b in self._filtered_backends(EllipticCurveBackend): + try: + return b.load_elliptic_curve_private_numbers(numbers) + except UnsupportedAlgorithm: + continue + + raise UnsupportedAlgorithm( + "This backend does not support this elliptic curve.", + _Reasons.UNSUPPORTED_ELLIPTIC_CURVE + ) + def elliptic_curve_public_key_from_numbers(self, numbers): + warnings.warn( + "elliptic_curve_public_key_from_numbers is deprecated and will " + "be removed in a future version.", + utils.DeprecatedIn06, + stacklevel=2 + ) for b in self._filtered_backends(EllipticCurveBackend): try: return b.elliptic_curve_public_key_from_numbers(numbers) @@ -320,6 +346,18 @@ class MultiBackend(object): _Reasons.UNSUPPORTED_ELLIPTIC_CURVE ) + def load_elliptic_curve_public_numbers(self, numbers): + for b in self._filtered_backends(EllipticCurveBackend): + try: + return b.load_elliptic_curve_public_numbers(numbers) + except UnsupportedAlgorithm: + continue + + raise UnsupportedAlgorithm( + "This backend does not support this elliptic curve.", + _Reasons.UNSUPPORTED_ELLIPTIC_CURVE + ) + def load_pem_private_key(self, data, password): for b in self._filtered_backends(PEMSerializationBackend): return b.load_pem_private_key(data, password) diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index 389ef0be..d0f69371 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -1015,6 +1015,15 @@ class Backend(object): ) def elliptic_curve_private_key_from_numbers(self, numbers): + warnings.warn( + "elliptic_curve_private_key_from_numbers is deprecated and will " + "be removed in a future version.", + utils.DeprecatedIn06, + stacklevel=2 + ) + return self.load_elliptic_curve_private_numbers(numbers) + + def load_elliptic_curve_private_numbers(self, numbers): public = numbers.public_numbers curve_nid = self._elliptic_curve_to_nid(public.curve) @@ -1034,6 +1043,15 @@ class Backend(object): numbers.public_numbers.curve) def elliptic_curve_public_key_from_numbers(self, numbers): + warnings.warn( + "elliptic_curve_public_key_from_numbers is deprecated and will be " + "removed in a future version.", + utils.DeprecatedIn06, + stacklevel=2 + ) + return self.load_elliptic_curve_public_numbers(numbers) + + def load_elliptic_curve_public_numbers(self, numbers): curve_nid = self._elliptic_curve_to_nid(numbers.curve) ctx = self._lib.EC_KEY_new_by_curve_name(curve_nid) diff --git a/cryptography/hazmat/primitives/asymmetric/ec.py b/cryptography/hazmat/primitives/asymmetric/ec.py index 98eca276..6dcf39cf 100644 --- a/cryptography/hazmat/primitives/asymmetric/ec.py +++ b/cryptography/hazmat/primitives/asymmetric/ec.py @@ -238,7 +238,10 @@ class EllipticCurvePublicNumbers(object): self._curve = curve def public_key(self, backend): - return backend.elliptic_curve_public_key_from_numbers(self) + try: + return backend.load_elliptic_curve_public_numbers(self) + except AttributeError: + return backend.elliptic_curve_public_key_from_numbers(self) @property def curve(self): @@ -268,7 +271,10 @@ class EllipticCurvePrivateNumbers(object): self._public_numbers = public_numbers def private_key(self, backend): - return backend.elliptic_curve_private_key_from_numbers(self) + try: + return backend.load_elliptic_curve_private_numbers(self) + except AttributeError: + return backend.elliptic_curve_private_key_from_numbers(self) @property def private_value(self): |