Skip to content

Commit 267f5ce

Browse files
committed
make cryptography_backend the default for RSAKey
1 parent c28f15a commit 267f5ce

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
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/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)