This repository was archived by the owner on Jan 10, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-16
lines changed Expand file tree Collapse file tree 2 files changed +17
-16
lines changed Original file line number Diff line number Diff line change 2727
2828try :
2929 import sign_m2crypto
30+ rsa_signer = sign_m2crypto .M2CryptoSigner
3031except ImportError :
31- sign_m2crypto = None
32- try :
33- import sign_pythonrsa
34- except ImportError :
35- sign_pythonrsa = None
32+ try :
33+ import sign_pythonrsa
34+ rsa_signer = sign_pythonrsa . PythonRSASigner . FromRSAKeyPath
35+ except ImportError :
36+ rsa_signer = None
3637
3738
3839gflags .ADOPT_module_key_flags (common_cli )
4748
4849def GetRSAKwargs ():
4950 if FLAGS .rsa_key_path :
50- if not sign_m2crypto and not sign_pythonrsa :
51+ if rsa_signer is None :
5152 print >> sys .stderr , 'Please install either M2Crypto or python-rsa'
5253 sys .exit (1 )
53- signer = (
54- sign_m2crypto .M2CryptoSigner if sign_m2crypto
55- else sign_pythonrsa .PythonRSASigner )
5654 return {
57- 'rsa_keys' : [signer (os .path .expanduser (path ))
55+ 'rsa_keys' : [rsa_signer (os .path .expanduser (path ))
5856 for path in FLAGS .rsa_key_path ],
5957 'auth_timeout_ms' : int (FLAGS .auth_timeout_s * 1000.0 ),
6058 }
Original file line number Diff line number Diff line change @@ -53,12 +53,15 @@ def _load_rsa_private_key(pem):
5353
5454class PythonRSASigner (object ):
5555 """Implements adb_protocol.AuthSigner using http://stuvel.eu/rsa."""
56- def __init__ (self , rsa_key_path = None , pub = None , priv = None ):
57- if rsa_key_path :
58- with open (rsa_key_path + '.pub' ) as f :
59- pub = f .read ()
60- with open (rsa_key_path ) as f :
61- priv = f .read ()
56+ @classmethod
57+ def FromRSAKeyPath (cls , rsa_key_path ):
58+ with open (rsa_key_path + '.pub' ) as f :
59+ pub = f .read ()
60+ with open (rsa_key_path ) as f :
61+ priv = f .read ()
62+ return cls (pub , priv )
63+
64+ def __init__ (self , pub = None , priv = None ):
6265 self .priv_key = _load_rsa_private_key (priv )
6366 self .pub_key = pub
6467
You can’t perform that action at this time.
0 commit comments