diff --git a/.travis.yml b/.travis.yml index 7e1201e6..ed6be1dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ env: - TOXENV=py27 - TOXENV=py33 - TOXENV=py34 + - TOXENV=pypy install: - pip install -r requirements-dev.txt - pip install -U tox codecov diff --git a/jose/jwk.py b/jose/jwk.py index 839b43b8..75814de6 100644 --- a/jose/jwk.py +++ b/jose/jwk.py @@ -2,7 +2,6 @@ import hashlib import hmac import six -import struct import Crypto.Hash.SHA256 import Crypto.Hash.SHA384 @@ -18,6 +17,13 @@ from jose.exceptions import JWSError from jose.exceptions import JOSEError +# 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: + _RSAKey = RSA.RsaKey + def get_algorithm_object(algorithm): """ @@ -204,7 +210,7 @@ def __init__(self, hash_alg): def process_prepare_key(self, key): - if isinstance(key, (RSA._RSAobj, RSAKey)): + if isinstance(key, (_RSAKey, RSAKey)): return key if isinstance(key, dict): diff --git a/setup.py b/setup.py index 1f1b4cda..83643b94 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,8 @@ import jose +import platform + from setuptools import setup @@ -22,6 +24,18 @@ def get_packages(package): ] +def get_install_requires(): + if platform.python_implementation() == 'PyPy': + crypto_lib = 'pycryptodome >=3.3.1, <3.4.0' + else: + crypto_lib = 'pycrypto >=2.6.0, <2.7.0' + return [ + crypto_lib, + 'six >=1.9.0, <1.10.0', + 'ecdsa <1.0', + ] + + setup( name='python-jose', version=jose.__version__, @@ -43,11 +57,8 @@ def get_packages(package): 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Utilities', ], - install_requires=[ - 'pycrypto >=2.6.0, <2.7.0', - 'six >=1.9.0, <1.10.0', - 'ecdsa <1.0', - ] + install_requires=get_install_requires() ) diff --git a/tox.ini b/tox.ini index ec2df7ba..51c1f204 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{26,27,33,34} +envlist = py{26,27,33,34,py} [testenv] commands =