diff --git a/README.rst b/README.rst index 71bc184f..cc17feca 100644 --- a/README.rst +++ b/README.rst @@ -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 ----- diff --git a/jose/backends/pycrypto_backend.py b/jose/backends/pycrypto_backend.py index a888f3e2..b5c24c60 100644 --- a/jose/backends/pycrypto_backend.py +++ b/jose/backends/pycrypto_backend.py @@ -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):