diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-09-27 10:18:04 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-09-27 10:18:26 -0500 |
commit | cff58d8d28ad15a8f7abaaa6ff5320a7d1f5b2f9 (patch) | |
tree | 8645894150322408d44d200c6e303fa20e868f99 | |
parent | e04f6fc6fcc5105ce66279eacd9df0683d538ee9 (diff) | |
download | cryptography-cff58d8d28ad15a8f7abaaa6ff5320a7d1f5b2f9.tar.gz cryptography-cff58d8d28ad15a8f7abaaa6ff5320a7d1f5b2f9.tar.bz2 cryptography-cff58d8d28ad15a8f7abaaa6ff5320a7d1f5b2f9.zip |
EC public/private key loader functions try deprecated as fallback
-rw-r--r-- | cryptography/hazmat/primitives/asymmetric/ec.py | 10 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_ec.py | 21 |
2 files changed, 29 insertions, 2 deletions
diff --git a/cryptography/hazmat/primitives/asymmetric/ec.py b/cryptography/hazmat/primitives/asymmetric/ec.py index 3893cc2f..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.load_elliptic_curve_public_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.load_elliptic_curve_private_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): diff --git a/tests/hazmat/primitives/test_ec.py b/tests/hazmat/primitives/test_ec.py index 65461f70..35505820 100644 --- a/tests/hazmat/primitives/test_ec.py +++ b/tests/hazmat/primitives/test_ec.py @@ -20,6 +20,7 @@ import os import pytest from cryptography import exceptions, utils +from cryptography.hazmat.backends.interfaces import EllipticCurveBackend from cryptography.hazmat.primitives import hashes, interfaces from cryptography.hazmat.primitives.asymmetric import ec @@ -70,6 +71,15 @@ class DummySignatureAlgorithm(object): pass +@utils.register_interface(EllipticCurveBackend) +class DeprecatedDummyECBackend(object): + def elliptic_curve_private_key_from_numbers(self, numbers): + return b"private_key" + + def elliptic_curve_public_key_from_numbers(self, numbers): + return b"public_key" + + @pytest.mark.elliptic def test_skip_curve_unsupported(backend): with pytest.raises(pytest.skip.Exception): @@ -282,3 +292,14 @@ class TestECDSAVectors(object): verifier.verify() else: verifier.verify() + + def test_deprecated_public_private_key_load(self): + b = DeprecatedDummyECBackend() + pub_numbers = ec.EllipticCurvePublicNumbers( + 2, + 3, + ec.SECT283K1() + ) + numbers = ec.EllipticCurvePrivateNumbers(1, pub_numbers) + assert numbers.private_key(b) == b"private_key" + assert pub_numbers.public_key(b) == b"public_key" |