Skip to content

Commit

Permalink
Merge pull request mpdavis#178 from bdraco/avoid_loading_ecdsa
Browse files Browse the repository at this point in the history
Avoid loading python-ecdsa when using the cryptography backend
  • Loading branch information
blag committed Jul 29, 2020
2 parents b4d4385 + d0a6268 commit 5cbebe0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
7 changes: 1 addition & 6 deletions jose/backends/cryptography_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

import six

try:
from ecdsa import SigningKey as EcdsaSigningKey, VerifyingKey as EcdsaVerifyingKey
except ImportError:
EcdsaSigningKey = EcdsaVerifyingKey = None

from jose.backends.base import Key
from jose.utils import base64_to_long, long_to_base64
from jose.constants import ALGORITHMS
Expand Down Expand Up @@ -46,7 +41,7 @@ def __init__(self, key, algorithm, cryptography_backend=default_backend):
self.prepared_key = key
return

if None not in (EcdsaSigningKey, EcdsaVerifyingKey) and isinstance(key, (EcdsaSigningKey, EcdsaVerifyingKey)):
if hasattr(key, 'to_pem'):
# convert to PEM and let cryptography below load it as PEM
key = key.to_pem().decode('utf-8')

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pycryptodome
six
rsa
ecdsa
ecdsa<0.15
pyasn1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _cryptography_version():
'pycrypto': ['pycrypto >=2.6.0, <2.7.0'] + pyasn1,
'pycryptodome': ['pycryptodome >=3.3.1, <4.0.0'] + pyasn1,
}
legacy_backend_requires = ['ecdsa <1.0', 'rsa'] + pyasn1
legacy_backend_requires = ['ecdsa <0.15', 'rsa'] + pyasn1
install_requires = ['six <2.0']

# TODO: work this into the extras selection instead.
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ deps =
pytest
pytest-cov
pytest-runner
-r{toxinidir}/requirements.txt

commands_pre =
# Remove the python-rsa and python-ecdsa backends
only: pip uninstall -y ecdsa rsa
Expand Down

0 comments on commit 5cbebe0

Please sign in to comment.