Skip to content

Commit 6b36628

Browse files
authored
Merge pull request #232 from asherf/crypto
Remove usage of deprecated Crypto library.
2 parents 01ec4ba + 5aa0c4e commit 6b36628

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

jose/utils.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,39 @@
33
import struct
44
import sys
55

6-
import six
7-
8-
if sys.version_info > (3,):
9-
# Deal with integer compatibilities between Python 2 and 3.
10-
# Using `from builtins import int` is not supported on AppEngine.
11-
long = int
12-
136

147
# Piggyback of the backends implementation of the function that converts a long
158
# to a bytes stream. Some plumbing is necessary to have the signatures match.
9+
1610
try:
17-
from Crypto.Util.number import long_to_bytes
18-
except ImportError:
19-
try:
20-
from cryptography.utils import int_to_bytes as _long_to_bytes
11+
from cryptography.utils import int_to_bytes as _long_to_bytes
2112

22-
def long_to_bytes(n, blocksize=0):
23-
return _long_to_bytes(n, blocksize or None)
13+
def long_to_bytes(n, blocksize=0):
14+
return _long_to_bytes(n, blocksize or None)
2415

25-
except ImportError:
26-
from ecdsa.ecdsa import int_to_string as _long_to_bytes
16+
except ImportError:
17+
from ecdsa.ecdsa import int_to_string as _long_to_bytes
2718

28-
def long_to_bytes(n, blocksize=0):
29-
ret = _long_to_bytes(n)
30-
if blocksize == 0:
31-
return ret
32-
else:
33-
assert len(ret) <= blocksize
34-
padding = blocksize - len(ret)
35-
return b'\x00' * padding + ret
19+
def long_to_bytes(n, blocksize=0):
20+
ret = _long_to_bytes(n)
21+
if blocksize == 0:
22+
return ret
23+
else:
24+
assert len(ret) <= blocksize
25+
padding = blocksize - len(ret)
26+
return b'\x00' * padding + ret
3627

3728

3829
def long_to_base64(data, size=0):
3930
return base64.urlsafe_b64encode(long_to_bytes(data, size)).strip(b'=')
4031

4132

4233
def int_arr_to_long(arr):
43-
return long(''.join(["%02x" % byte for byte in arr]), 16)
34+
return int(''.join(["%02x" % byte for byte in arr]), 16)
4435

4536

4637
def base64_to_long(data):
47-
if isinstance(data, six.text_type):
38+
if isinstance(data, str):
4839
data = data.encode("ascii")
4940

5041
# urlsafe_b64decode will happily convert b64encoded data

0 commit comments

Comments
 (0)