|
1 | 1 | # from __future__ import print_function |
2 | 2 | import hashlib |
3 | 3 | import os |
| 4 | +import string |
4 | 5 | import sys |
5 | 6 | import array |
6 | 7 |
|
7 | 8 | import pytest |
8 | 9 | from cryptography.hazmat.backends import default_backend |
9 | 10 | from cryptography.hazmat.primitives.asymmetric import ec |
10 | | -from oic import rndstr |
11 | 11 |
|
12 | | -from cryptojwt.exception import MissingKey, BadSyntax, HeaderError |
| 12 | +from cryptojwt.exception import BadSyntax |
| 13 | +from cryptojwt.exception import HeaderError |
| 14 | +from cryptojwt.exception import MissingKey |
13 | 15 | from cryptojwt.exception import Unsupported |
14 | 16 | from cryptojwt.exception import VerificationError |
15 | | -from cryptojwt.jwe.exception import UnsupportedBitLength, \ |
16 | | - NoSuitableEncryptionKey, WrongEncryptionAlgorithm, NoSuitableDecryptionKey |
17 | | - |
| 17 | +from cryptojwt.jwe.exception import NoSuitableDecryptionKey |
| 18 | +from cryptojwt.jwe.exception import NoSuitableEncryptionKey |
| 19 | +from cryptojwt.jwe.exception import UnsupportedBitLength |
| 20 | +from cryptojwt.jwe.exception import WrongEncryptionAlgorithm |
18 | 21 | from cryptojwt.utils import b64e, as_bytes |
19 | 22 |
|
20 | 23 | from cryptojwt.jwe.aes import AES_CBCEncrypter |
|
34 | 37 |
|
35 | 38 | __author__ = 'rohe0002' |
36 | 39 |
|
| 40 | +try: |
| 41 | + import random.SystemRandom as rnd |
| 42 | +except ImportError: |
| 43 | + import random as rnd |
| 44 | + |
| 45 | + |
| 46 | +def rndstr(size=16): |
| 47 | + """ |
| 48 | + Returns a string of random ascii characters or digits |
| 49 | +
|
| 50 | + :param size: The length of the string |
| 51 | + :return: string |
| 52 | + """ |
| 53 | + _basech = string.ascii_letters + string.digits |
| 54 | + return "".join([rnd.choice(_basech) for _ in range(size)]) |
| 55 | + |
37 | 56 |
|
38 | 57 | def intarr2bytes(arr): |
39 | 58 | return array.array('B', arr).tostring() |
|
0 commit comments