Skip to content

Commit

Permalink
Merge pull request #122 from mattsb42-aws/pyca-default
Browse files Browse the repository at this point in the history
make cryptography_backend the default for RSAKey
  • Loading branch information
zejn authored Apr 2, 2019
2 parents c28f15a + f96daec commit 595dd71
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions jose/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

try:
from jose.backends.pycrypto_backend import RSAKey # noqa: F401
from jose.backends.cryptography_backend import CryptographyRSAKey as RSAKey # noqa: F401
except ImportError:
try:
from jose.backends.cryptography_backend import CryptographyRSAKey as RSAKey # noqa: F401
from jose.backends.pycrypto_backend import RSAKey # noqa: F401
except ImportError:
from jose.backends.rsa_backend import RSAKey # noqa: F401

Expand Down
3 changes: 2 additions & 1 deletion tests/algorithms/test_RSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,9 @@ def test_pycrypto_RSA_key_instance():
@pytest.mark.pycrypto
@pytest.mark.pycryptodome
@pytest.mark.parametrize("private_key", PRIVATE_KEYS)
@pytest.mark.skipif(None in (PyCryptoRSA, PyCryptoRSAKey), reason="Pycrypto/dome backend not available")
def test_pycrypto_unencoded_cleartext(private_key):
key = RSAKey(private_key, ALGORITHMS.RS256)
key = PyCryptoRSAKey(private_key, ALGORITHMS.RS256)
msg = b'test'
signature = key.sign(msg)
public_key = key.public_key()
Expand Down
35 changes: 35 additions & 0 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Test the default import handling."""
try:
from jose.backends.rsa_backend import RSAKey as PurePythonRSAKey
except ImportError:
PurePythonRSAKey = None
try:
from jose.backends.cryptography_backend import CryptographyRSAKey, CryptographyECKey
except ImportError:
CryptographyRSAKey = CryptographyECKey = None
try:
from jose.backends.pycrypto_backend import RSAKey as PyCryptoRSAKey
except ImportError:
PyCryptoRSAKey = None
try:
from jose.backends.ecdsa_backend import ECDSAECKey as PurePythonECDSAKey
except ImportError:
PurePythonRSAKey = None

from jose.backends import ECKey, RSAKey


def test_default_ec_backend():
if CryptographyECKey is not None:
assert ECKey is CryptographyECKey
else:
assert ECKey is PurePythonECDSAKey


def test_default_rsa_backend():
if CryptographyRSAKey is not None:
assert RSAKey is CryptographyRSAKey
elif PyCryptoRSAKey is not None:
assert RSAKey is PyCryptoRSAKey
else:
assert RSAKey is PurePythonRSAKey

0 comments on commit 595dd71

Please sign in to comment.