@@ -87,13 +87,14 @@ def prepare_HS_key(key):
8787 })
8888
8989 def prepare_RS_key (key ):
90+ if isinstance (key , RSA ._RSAobj ):
91+ return key
92+
9093 if isinstance (key , basestring ):
9194 if isinstance (key , unicode ):
9295 key = key .encode ('utf-8' )
9396
9497 key = RSA .importKey (key )
95- elif isinstance (key , RSA ._RSAobj ):
96- pass
9798 else :
9899 raise TypeError ('Expecting a PEM- or RSA-formatted key.' )
99100
@@ -127,6 +128,10 @@ def prepare_RS_key(key):
127128 })
128129
129130 def prepare_ES_key (key ):
131+ if isinstance (key , ecdsa .SigningKey ) or \
132+ isinstance (key , ecdsa .VerifyingKey ):
133+ return key
134+
130135 if isinstance (key , basestring ):
131136 if isinstance (key , unicode ):
132137 key = key .encode ('utf-8' )
@@ -141,10 +146,9 @@ def prepare_ES_key(key):
141146 key = ecdsa .SigningKey .from_pem (key )
142147 except :
143148 raise
144- elif isinstance (key , ecdsa .SigningKey ) or isinstance (key , ecdsa .VerifyingKey ):
145- pass
146149 else :
147- raise TypeError ("Expecting a PEM-formatted key." )
150+ raise TypeError ('Expecting a PEM-formatted key.' )
151+
148152 return key
149153
150154 prepare_key_methods .update ({
@@ -157,7 +161,6 @@ def prepare_ES_key(key):
157161 pass
158162
159163
160-
161164def constant_time_compare (val1 , val2 ):
162165 """
163166 Returns True if the two strings are equal, False otherwise.
@@ -308,7 +311,7 @@ def verify_signature(payload, signing_input, header, signature, key='',
308311 if 'nbf' in payload and verify_expiration :
309312 utc_timestamp = timegm (datetime .utcnow ().utctimetuple ())
310313 if payload ['nbf' ] > (utc_timestamp + leeway ):
311- raise ExpiredSignature (" Signature not yet valid" )
314+ raise ExpiredSignature (' Signature not yet valid' )
312315
313316 if 'exp' in payload and verify_expiration :
314317 utc_timestamp = timegm (datetime .utcnow ().utctimetuple ())
0 commit comments