aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cryptography/hazmat/primitives/asymmetric/ec.py10
-rw-r--r--tests/hazmat/primitives/test_ec.py21
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"