1
1
import sys
2
2
3
3
try :
4
- from Crypto .PublicKey import RSA
4
+ from Crypto .PublicKey import RSA as PyCryptoRSA
5
+ from jose .backends .pycrypto_backend import RSAKey as PyCryptoRSAKey
5
6
except ImportError :
6
- RSA = None
7
+ PyCryptoRSA = PyCryptoRSAKey = None
7
8
8
9
try :
9
10
from cryptography .hazmat .backends import default_backend
10
- from cryptography .hazmat .primitives .asymmetric import rsa
11
+ from cryptography .hazmat .primitives .asymmetric import rsa as pyca_rsa
12
+ from jose .backends .cryptography_backend import CryptographyRSAKey
11
13
except ImportError :
12
- default_backend = rsa = None
14
+ default_backend = pyca_rsa = CryptographyRSAKey = None
13
15
14
16
from jose .backends import RSAKey
15
17
from jose .constants import ALGORITHMS
77
79
78
80
@pytest .mark .pycrypto
79
81
@pytest .mark .pycryptodome
80
- @pytest .mark .skipif (RSA is None , reason = "Pycrypto/dome backend not available" )
82
+ @pytest .mark .skipif (None in ( PyCryptoRSA , PyCryptoRSAKey ) , reason = "Pycrypto/dome backend not available" )
81
83
def test_pycrypto_RSA_key_instance ():
82
- key = RSA .construct ((long (
84
+ key = PyCryptoRSA .construct ((long (
83
85
26057131595212989515105618545799160306093557851986992545257129318694524535510983041068168825614868056510242030438003863929818932202262132630250203397069801217463517914103389095129323580576852108653940669240896817348477800490303630912852266209307160550655497615975529276169196271699168537716821419779900117025818140018436554173242441334827711966499484119233207097432165756707507563413323850255548329534279691658369466534587631102538061857114141268972476680597988266772849780811214198186940677291891818952682545840788356616771009013059992237747149380197028452160324144544057074406611859615973035412993832273216732343819 ),
84
86
long (65537 )))
85
- RSAKey (key , ALGORITHMS .RS256 )
87
+ PyCryptoRSAKey (key , ALGORITHMS .RS256 )
86
88
87
89
# TODO: Unclear why this test was marked as only for pycrypto
88
90
@pytest .mark .pycrypto
@@ -99,17 +101,17 @@ def test_pycrypto_unencoded_cleartext():
99
101
100
102
@pytest .mark .cryptography
101
103
@pytest .mark .skipif (
102
- None in (default_backend , rsa ),
104
+ None in (default_backend , pyca_rsa , CryptographyRSAKey ),
103
105
reason = "Cryptography backend not available"
104
106
)
105
107
def test_cryptography_RSA_key_instance ():
106
108
107
- key = rsa .RSAPublicNumbers (
109
+ key = pyca_rsa .RSAPublicNumbers (
108
110
long (65537 ),
109
111
long (26057131595212989515105618545799160306093557851986992545257129318694524535510983041068168825614868056510242030438003863929818932202262132630250203397069801217463517914103389095129323580576852108653940669240896817348477800490303630912852266209307160550655497615975529276169196271699168537716821419779900117025818140018436554173242441334827711966499484119233207097432165756707507563413323850255548329534279691658369466534587631102538061857114141268972476680597988266772849780811214198186940677291891818952682545840788356616771009013059992237747149380197028452160324144544057074406611859615973035412993832273216732343819 ),
110
112
).public_key (default_backend ())
111
113
112
- pubkey = RSAKey (key , ALGORITHMS .RS256 )
114
+ pubkey = CryptographyRSAKey (key , ALGORITHMS .RS256 )
113
115
assert pubkey .is_public ()
114
116
115
117
pem = pubkey .to_pem ()
0 commit comments