Skip to content

Commit 595dd71

Browse files
authored
Merge pull request #122 from mattsb42-aws/pyca-default
make cryptography_backend the default for RSAKey
2 parents c28f15a + f96daec commit 595dd71

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

jose/backends/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
try:
3-
from jose.backends.pycrypto_backend import RSAKey # noqa: F401
3+
from jose.backends.cryptography_backend import CryptographyRSAKey as RSAKey # noqa: F401
44
except ImportError:
55
try:
6-
from jose.backends.cryptography_backend import CryptographyRSAKey as RSAKey # noqa: F401
6+
from jose.backends.pycrypto_backend import RSAKey # noqa: F401
77
except ImportError:
88
from jose.backends.rsa_backend import RSAKey # noqa: F401
99

tests/algorithms/test_RSA.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,9 @@ def test_pycrypto_RSA_key_instance():
345345
@pytest.mark.pycrypto
346346
@pytest.mark.pycryptodome
347347
@pytest.mark.parametrize("private_key", PRIVATE_KEYS)
348+
@pytest.mark.skipif(None in (PyCryptoRSA, PyCryptoRSAKey), reason="Pycrypto/dome backend not available")
348349
def test_pycrypto_unencoded_cleartext(private_key):
349-
key = RSAKey(private_key, ALGORITHMS.RS256)
350+
key = PyCryptoRSAKey(private_key, ALGORITHMS.RS256)
350351
msg = b'test'
351352
signature = key.sign(msg)
352353
public_key = key.public_key()

tests/test_backends.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Test the default import handling."""
2+
try:
3+
from jose.backends.rsa_backend import RSAKey as PurePythonRSAKey
4+
except ImportError:
5+
PurePythonRSAKey = None
6+
try:
7+
from jose.backends.cryptography_backend import CryptographyRSAKey, CryptographyECKey
8+
except ImportError:
9+
CryptographyRSAKey = CryptographyECKey = None
10+
try:
11+
from jose.backends.pycrypto_backend import RSAKey as PyCryptoRSAKey
12+
except ImportError:
13+
PyCryptoRSAKey = None
14+
try:
15+
from jose.backends.ecdsa_backend import ECDSAECKey as PurePythonECDSAKey
16+
except ImportError:
17+
PurePythonRSAKey = None
18+
19+
from jose.backends import ECKey, RSAKey
20+
21+
22+
def test_default_ec_backend():
23+
if CryptographyECKey is not None:
24+
assert ECKey is CryptographyECKey
25+
else:
26+
assert ECKey is PurePythonECDSAKey
27+
28+
29+
def test_default_rsa_backend():
30+
if CryptographyRSAKey is not None:
31+
assert RSAKey is CryptographyRSAKey
32+
elif PyCryptoRSAKey is not None:
33+
assert RSAKey is PyCryptoRSAKey
34+
else:
35+
assert RSAKey is PurePythonRSAKey

0 commit comments

Comments
 (0)