@@ -80,41 +80,41 @@ def test_hmac_should_throw_exception_if_key_is_pem_public_key(self):
8080 algo = HMACAlgorithm (HMACAlgorithm .SHA256 )
8181
8282 with pytest .raises (InvalidKeyError ):
83- with open (key_path ("testkey2_rsa.pub.pem" ), "r" ) as keyfile :
83+ with open (key_path ("testkey2_rsa.pub.pem" )) as keyfile :
8484 algo .prepare_key (keyfile .read ())
8585
8686 def test_hmac_should_throw_exception_if_key_is_x509_certificate (self ):
8787 algo = HMACAlgorithm (HMACAlgorithm .SHA256 )
8888
8989 with pytest .raises (InvalidKeyError ):
90- with open (key_path ("testkey_rsa.cer" ), "r" ) as keyfile :
90+ with open (key_path ("testkey_rsa.cer" )) as keyfile :
9191 algo .prepare_key (keyfile .read ())
9292
9393 def test_hmac_should_throw_exception_if_key_is_ssh_public_key (self ):
9494 algo = HMACAlgorithm (HMACAlgorithm .SHA256 )
9595
9696 with pytest .raises (InvalidKeyError ):
97- with open (key_path ("testkey_rsa.pub" ), "r" ) as keyfile :
97+ with open (key_path ("testkey_rsa.pub" )) as keyfile :
9898 algo .prepare_key (keyfile .read ())
9999
100100 def test_hmac_should_throw_exception_if_key_is_x509_cert (self ):
101101 algo = HMACAlgorithm (HMACAlgorithm .SHA256 )
102102
103103 with pytest .raises (InvalidKeyError ):
104- with open (key_path ("testkey2_rsa.pub.pem" ), "r" ) as keyfile :
104+ with open (key_path ("testkey2_rsa.pub.pem" )) as keyfile :
105105 algo .prepare_key (keyfile .read ())
106106
107107 def test_hmac_should_throw_exception_if_key_is_pkcs1_pem_public (self ):
108108 algo = HMACAlgorithm (HMACAlgorithm .SHA256 )
109109
110110 with pytest .raises (InvalidKeyError ):
111- with open (key_path ("testkey_pkcs1.pub.pem" ), "r" ) as keyfile :
111+ with open (key_path ("testkey_pkcs1.pub.pem" )) as keyfile :
112112 algo .prepare_key (keyfile .read ())
113113
114114 def test_hmac_jwk_should_parse_and_verify (self ):
115115 algo = HMACAlgorithm (HMACAlgorithm .SHA256 )
116116
117- with open (key_path ("jwk_hmac.json" ), "r" ) as keyfile :
117+ with open (key_path ("jwk_hmac.json" )) as keyfile :
118118 key = algo .from_jwk (keyfile .read ())
119119
120120 signature = algo .sign (b"Hello World!" , key )
@@ -129,7 +129,7 @@ def test_hmac_to_jwk_returns_correct_values(self):
129129 def test_hmac_from_jwk_should_raise_exception_if_not_hmac_key (self ):
130130 algo = HMACAlgorithm (HMACAlgorithm .SHA256 )
131131
132- with open (key_path ("jwk_rsa_pub.json" ), "r" ) as keyfile :
132+ with open (key_path ("jwk_rsa_pub.json" )) as keyfile :
133133 with pytest .raises (InvalidKeyError ):
134134 algo .from_jwk (keyfile .read ())
135135
@@ -139,7 +139,7 @@ def test_hmac_from_jwk_should_raise_exception_if_not_hmac_key(self):
139139 def test_rsa_should_parse_pem_public_key (self ):
140140 algo = RSAAlgorithm (RSAAlgorithm .SHA256 )
141141
142- with open (key_path ("testkey2_rsa.pub.pem" ), "r" ) as pem_key :
142+ with open (key_path ("testkey2_rsa.pub.pem" )) as pem_key :
143143 algo .prepare_key (pem_key .read ())
144144
145145 @pytest .mark .skipif (
@@ -157,7 +157,7 @@ def test_rsa_should_accept_pem_private_key_bytes(self):
157157 def test_rsa_should_accept_unicode_key (self ):
158158 algo = RSAAlgorithm (RSAAlgorithm .SHA256 )
159159
160- with open (key_path ("testkey_rsa.priv" ), "r" ) as rsa_key :
160+ with open (key_path ("testkey_rsa.priv" )) as rsa_key :
161161 algo .prepare_key (force_unicode (rsa_key .read ()))
162162
163163 @pytest .mark .skipif (
@@ -190,7 +190,7 @@ def test_rsa_verify_should_return_false_if_signature_invalid(self):
190190
191191 sig += force_bytes ("123" ) # Signature is now invalid
192192
193- with open (key_path ("testkey_rsa.pub" ), "r" ) as keyfile :
193+ with open (key_path ("testkey_rsa.pub" )) as keyfile :
194194 pub_key = algo .prepare_key (keyfile .read ())
195195
196196 result = algo .verify (message , pub_key , sig )
@@ -208,14 +208,10 @@ def test_ec_jwk_public_and_private_keys_should_parse_and_verify(self):
208208 for (curve , hash ) in tests .items ():
209209 algo = ECAlgorithm (hash )
210210
211- with open (
212- key_path ("jwk_ec_pub_{}.json" .format (curve )), "r"
213- ) as keyfile :
211+ with open (key_path (f"jwk_ec_pub_{ curve } .json" )) as keyfile :
214212 pub_key = algo .from_jwk (keyfile .read ())
215213
216- with open (
217- key_path ("jwk_ec_key_{}.json" .format (curve )), "r"
218- ) as keyfile :
214+ with open (key_path (f"jwk_ec_key_{ curve } .json" )) as keyfile :
219215 priv_key = algo .from_jwk (keyfile .read ())
220216
221217 signature = algo .sign (force_bytes ("Hello World!" ), priv_key )
@@ -290,10 +286,10 @@ def test_ec_jwk_fails_on_invalid_json(self):
290286 def test_rsa_jwk_public_and_private_keys_should_parse_and_verify (self ):
291287 algo = RSAAlgorithm (RSAAlgorithm .SHA256 )
292288
293- with open (key_path ("jwk_rsa_pub.json" ), "r" ) as keyfile :
289+ with open (key_path ("jwk_rsa_pub.json" )) as keyfile :
294290 pub_key = algo .from_jwk (keyfile .read ())
295291
296- with open (key_path ("jwk_rsa_key.json" ), "r" ) as keyfile :
292+ with open (key_path ("jwk_rsa_key.json" )) as keyfile :
297293 priv_key = algo .from_jwk (keyfile .read ())
298294
299295 signature = algo .sign (force_bytes ("Hello World!" ), priv_key )
@@ -305,7 +301,7 @@ def test_rsa_jwk_public_and_private_keys_should_parse_and_verify(self):
305301 def test_rsa_private_key_to_jwk_works_with_from_jwk (self ):
306302 algo = RSAAlgorithm (RSAAlgorithm .SHA256 )
307303
308- with open (key_path ("testkey_rsa.priv" ), "r" ) as rsa_key :
304+ with open (key_path ("testkey_rsa.priv" )) as rsa_key :
309305 orig_key = algo .prepare_key (force_unicode (rsa_key .read ()))
310306
311307 parsed_key = algo .from_jwk (algo .to_jwk (orig_key ))
@@ -321,7 +317,7 @@ def test_rsa_private_key_to_jwk_works_with_from_jwk(self):
321317 def test_rsa_public_key_to_jwk_works_with_from_jwk (self ):
322318 algo = RSAAlgorithm (RSAAlgorithm .SHA256 )
323319
324- with open (key_path ("testkey_rsa.pub" ), "r" ) as rsa_key :
320+ with open (key_path ("testkey_rsa.pub" )) as rsa_key :
325321 orig_key = algo .prepare_key (force_unicode (rsa_key .read ()))
326322
327323 parsed_key = algo .from_jwk (algo .to_jwk (orig_key ))
@@ -333,7 +329,7 @@ def test_rsa_public_key_to_jwk_works_with_from_jwk(self):
333329 def test_rsa_jwk_private_key_with_other_primes_is_invalid (self ):
334330 algo = RSAAlgorithm (RSAAlgorithm .SHA256 )
335331
336- with open (key_path ("jwk_rsa_key.json" ), "r" ) as keyfile :
332+ with open (key_path ("jwk_rsa_key.json" )) as keyfile :
337333 with pytest .raises (InvalidKeyError ):
338334 keydata = json .loads (keyfile .read ())
339335 keydata ["oth" ] = []
@@ -346,7 +342,7 @@ def test_rsa_jwk_private_key_with_other_primes_is_invalid(self):
346342 def test_rsa_jwk_private_key_with_missing_values_is_invalid (self ):
347343 algo = RSAAlgorithm (RSAAlgorithm .SHA256 )
348344
349- with open (key_path ("jwk_rsa_key.json" ), "r" ) as keyfile :
345+ with open (key_path ("jwk_rsa_key.json" )) as keyfile :
350346 with pytest .raises (InvalidKeyError ):
351347 keydata = json .loads (keyfile .read ())
352348 del keydata ["p" ]
@@ -359,7 +355,7 @@ def test_rsa_jwk_private_key_with_missing_values_is_invalid(self):
359355 def test_rsa_jwk_private_key_can_recover_prime_factors (self ):
360356 algo = RSAAlgorithm (RSAAlgorithm .SHA256 )
361357
362- with open (key_path ("jwk_rsa_key.json" ), "r" ) as keyfile :
358+ with open (key_path ("jwk_rsa_key.json" )) as keyfile :
363359 keybytes = keyfile .read ()
364360 control_key = algo .from_jwk (keybytes ).private_numbers ()
365361
@@ -383,7 +379,7 @@ def test_rsa_jwk_private_key_can_recover_prime_factors(self):
383379 def test_rsa_jwk_private_key_with_missing_required_values_is_invalid (self ):
384380 algo = RSAAlgorithm (RSAAlgorithm .SHA256 )
385381
386- with open (key_path ("jwk_rsa_key.json" ), "r" ) as keyfile :
382+ with open (key_path ("jwk_rsa_key.json" )) as keyfile :
387383 with pytest .raises (InvalidKeyError ):
388384 keydata = json .loads (keyfile .read ())
389385 del keydata ["p" ]
@@ -410,7 +406,7 @@ def test_rsa_jwk_raises_exception_if_not_a_valid_key(self):
410406 def test_rsa_to_jwk_returns_correct_values_for_public_key (self ):
411407 algo = RSAAlgorithm (RSAAlgorithm .SHA256 )
412408
413- with open (key_path ("testkey_rsa.pub" ), "r" ) as keyfile :
409+ with open (key_path ("testkey_rsa.pub" )) as keyfile :
414410 pub_key = algo .prepare_key (keyfile .read ())
415411
416412 key = algo .to_jwk (pub_key )
@@ -436,7 +432,7 @@ def test_rsa_to_jwk_returns_correct_values_for_public_key(self):
436432 def test_rsa_to_jwk_returns_correct_values_for_private_key (self ):
437433 algo = RSAAlgorithm (RSAAlgorithm .SHA256 )
438434
439- with open (key_path ("testkey_rsa.priv" ), "r" ) as keyfile :
435+ with open (key_path ("testkey_rsa.priv" )) as keyfile :
440436 priv_key = algo .prepare_key (keyfile .read ())
441437
442438 key = algo .to_jwk (priv_key )
@@ -504,7 +500,7 @@ def test_rsa_to_jwk_raises_exception_on_invalid_key(self):
504500 def test_rsa_from_jwk_raises_exception_on_invalid_key (self ):
505501 algo = RSAAlgorithm (RSAAlgorithm .SHA256 )
506502
507- with open (key_path ("jwk_hmac.json" ), "r" ) as keyfile :
503+ with open (key_path ("jwk_hmac.json" )) as keyfile :
508504 with pytest .raises (InvalidKeyError ):
509505 algo .from_jwk (keyfile .read ())
510506
@@ -532,7 +528,7 @@ def test_ec_should_accept_pem_private_key_bytes(self):
532528 def test_ec_should_accept_ssh_public_key_bytes (self ):
533529 algo = ECAlgorithm (ECAlgorithm .SHA256 )
534530
535- with open (key_path ("testkey_ec_ssh.pub" ), "r" ) as ec_key :
531+ with open (key_path ("testkey_ec_ssh.pub" )) as ec_key :
536532 algo .prepare_key (ec_key .read ())
537533
538534 @pytest .mark .skipif (
@@ -554,7 +550,7 @@ def test_ec_verify_should_return_false_if_signature_invalid(self):
554550 )
555551 )
556552
557- with open (key_path ("testkey_ec.pub" ), "r" ) as keyfile :
553+ with open (key_path ("testkey_ec.pub" )) as keyfile :
558554 pub_key = algo .prepare_key (keyfile .read ())
559555
560556 result = algo .verify (message , pub_key , sig )
@@ -570,7 +566,7 @@ def test_ec_verify_should_return_false_if_signature_wrong_length(self):
570566
571567 sig = base64 .b64decode (force_bytes ("AC+m4Jf/xI3guAC6w0w3" ))
572568
573- with open (key_path ("testkey_ec.pub" ), "r" ) as keyfile :
569+ with open (key_path ("testkey_ec.pub" )) as keyfile :
574570 pub_key = algo .prepare_key (keyfile .read ())
575571
576572 result = algo .verify (message , pub_key , sig )
@@ -584,11 +580,11 @@ def test_rsa_pss_sign_then_verify_should_return_true(self):
584580
585581 message = force_bytes ("Hello World!" )
586582
587- with open (key_path ("testkey_rsa.priv" ), "r" ) as keyfile :
583+ with open (key_path ("testkey_rsa.priv" )) as keyfile :
588584 priv_key = algo .prepare_key (keyfile .read ())
589585 sig = algo .sign (message , priv_key )
590586
591- with open (key_path ("testkey_rsa.pub" ), "r" ) as keyfile :
587+ with open (key_path ("testkey_rsa.pub" )) as keyfile :
592588 pub_key = algo .prepare_key (keyfile .read ())
593589
594590 result = algo .verify (message , pub_key , sig )
@@ -615,7 +611,7 @@ def test_rsa_pss_verify_should_return_false_if_signature_invalid(self):
615611
616612 jwt_sig += force_bytes ("123" ) # Signature is now invalid
617613
618- with open (key_path ("testkey_rsa.pub" ), "r" ) as keyfile :
614+ with open (key_path ("testkey_rsa.pub" )) as keyfile :
619615 jwt_pub_key = algo .prepare_key (keyfile .read ())
620616
621617 result = algo .verify (jwt_message , jwt_pub_key , jwt_sig )
0 commit comments