Skip to content

Commit

Permalink
Merge pull request #8 from jeethu/pypy-support
Browse files Browse the repository at this point in the history
PyPy support
  • Loading branch information
Michael Davis committed Nov 24, 2015
2 parents 0913db2 + 6c26bee commit 24f7f7a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions jose/jwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import hashlib
import hmac
import six
import struct

import Crypto.Hash.SHA256
import Crypto.Hash.SHA384
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down
21 changes: 16 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import jose

import platform

from setuptools import setup


Expand All @@ -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__,
Expand All @@ -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()
)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{26,27,33,34}
envlist = py{26,27,33,34,py}

[testenv]
commands =
Expand Down

0 comments on commit 24f7f7a

Please sign in to comment.