Skip to content

Commit

Permalink
use pycrpyto if it is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Davis committed Jan 16, 2018
1 parent 98406bc commit 7b9310b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ Installation
$ pip install python-jose


Custom Backends
---------------

As of 2.0.0, python-jose uses pycryptodome by default for RSA signing and verification. If
necessary, other RSA backends are supported. Both pycrpyto and crytography are options.

In order to use a custom backend, install python-jose with the appropriate extra.

::
$ pip install python-jose[pycrypto]
$ pip install python-jose[crytography]

Usage
-----

Expand Down
13 changes: 8 additions & 5 deletions jose/backends/pycrypto_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
from jose.exceptions import JWKError
from jose.utils import base64url_decode

# PyCryptodome's RSA module doesn't have PyCrypto's _RSAobj class
# Instead it has a class named RsaKey, which serves the same purpose.
if hasattr(RSA, '_RSAobj'):
_RSAKey = RSA._RSAobj
else:

# We default to using PyCryptodome, however, if PyCrypto is installed, it is
# used instead. This is so that environments that require the use of PyCrypto
# are still supported.
if hasattr(RSA, 'RsaKey'):
_RSAKey = RSA.RsaKey
else:
_RSAKey = RSA._RSAobj



class RSAKey(Key):
Expand Down

0 comments on commit 7b9310b

Please sign in to comment.