Skip to content

Commit 7b9310b

Browse files
author
Michael Davis
committed
use pycrpyto if it is installed
1 parent 98406bc commit 7b9310b

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

README.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ Installation
3131
$ pip install python-jose
3232

3333

34+
Custom Backends
35+
---------------
36+
37+
As of 2.0.0, python-jose uses pycryptodome by default for RSA signing and verification. If
38+
necessary, other RSA backends are supported. Both pycrpyto and crytography are options.
39+
40+
In order to use a custom backend, install python-jose with the appropriate extra.
41+
42+
::
43+
$ pip install python-jose[pycrypto]
44+
$ pip install python-jose[crytography]
45+
3446
Usage
3547
-----
3648

jose/backends/pycrypto_backend.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
from jose.exceptions import JWKError
1515
from jose.utils import base64url_decode
1616

17-
# PyCryptodome's RSA module doesn't have PyCrypto's _RSAobj class
18-
# Instead it has a class named RsaKey, which serves the same purpose.
19-
if hasattr(RSA, '_RSAobj'):
20-
_RSAKey = RSA._RSAobj
21-
else:
17+
18+
# We default to using PyCryptodome, however, if PyCrypto is installed, it is
19+
# used instead. This is so that environments that require the use of PyCrypto
20+
# are still supported.
21+
if hasattr(RSA, 'RsaKey'):
2222
_RSAKey = RSA.RsaKey
23+
else:
24+
_RSAKey = RSA._RSAobj
25+
2326

2427

2528
class RSAKey(Key):

0 commit comments

Comments
 (0)