|
3 | 3 | import struct
|
4 | 4 | import sys
|
5 | 5 |
|
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 |
| - |
13 | 6 |
|
14 | 7 | # Piggyback of the backends implementation of the function that converts a long
|
15 | 8 | # to a bytes stream. Some plumbing is necessary to have the signatures match.
|
| 9 | + |
16 | 10 | 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 |
21 | 12 |
|
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) |
24 | 15 |
|
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 |
27 | 18 |
|
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 |
36 | 27 |
|
37 | 28 |
|
38 | 29 | def long_to_base64(data, size=0):
|
39 | 30 | return base64.urlsafe_b64encode(long_to_bytes(data, size)).strip(b'=')
|
40 | 31 |
|
41 | 32 |
|
42 | 33 | 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) |
44 | 35 |
|
45 | 36 |
|
46 | 37 | def base64_to_long(data):
|
47 |
| - if isinstance(data, six.text_type): |
| 38 | + if isinstance(data, str): |
48 | 39 | data = data.encode("ascii")
|
49 | 40 |
|
50 | 41 | # urlsafe_b64decode will happily convert b64encoded data
|
|
0 commit comments