1010
1111
1212class TestJWEJSON (TestCase ):
13+ rsa_key = RSAKey .generate_key ()
14+ ec_key = ECKey .generate_key ()
15+
1316 def test_multiple_recipients_with_key (self ):
14- key1 = RSAKey .generate_key ()
15- key2 = ECKey .generate_key ()
1617 obj = GeneralJSONEncryption ({"enc" : "A128CBC-HS256" }, b"i" )
17- obj .add_recipient ({"alg" : "RSA-OAEP" }, key1 )
18- obj .add_recipient ({"alg" : "ECDH-ES+A128KW" }, key2 )
18+ obj .add_recipient ({"alg" : "RSA-OAEP" }, self . rsa_key )
19+ obj .add_recipient ({"alg" : "ECDH-ES+A128KW" }, self . ec_key )
1920 value = jwe .encrypt_json (obj , None )
2021 self .assertIn ("recipients" , value )
2122 self .assertEqual (len (value ["recipients" ]), 2 )
@@ -33,7 +34,7 @@ def test_multiple_recipients_without_key(self):
3334 def test_multiple_recipients_with_direct_mode (self ):
3435 obj = GeneralJSONEncryption ({"enc" : "A128CBC-HS256" }, b"i" )
3536 obj .add_recipient ({"alg" : "dir" }, OctKey .generate_key ())
36- obj .add_recipient ({"alg" : "RSA-OAEP" }, RSAKey . generate_key () )
37+ obj .add_recipient ({"alg" : "RSA-OAEP" }, self . rsa_key )
3738 self .assertRaises (
3839 ConflictAlgorithmError ,
3940 jwe .encrypt_json ,
@@ -42,26 +43,23 @@ def test_multiple_recipients_with_direct_mode(self):
4243
4344 def test_with_aad (self ):
4445 obj = GeneralJSONEncryption ({"enc" : "A128CBC-HS256" }, b"i" , aad = b"foo" )
45- key1 = RSAKey .generate_key ()
46- obj .add_recipient ({"alg" : "RSA-OAEP" }, key1 )
46+ obj .add_recipient ({"alg" : "RSA-OAEP" }, self .rsa_key )
4747 value = jwe .encrypt_json (obj , None )
48- obj1 = jwe .decrypt_json (value , key1 )
48+ obj1 = jwe .decrypt_json (value , self . rsa_key )
4949 self .assertEqual (obj1 .aad , b"foo" )
5050
5151 def test_decode_multiple_recipients (self ):
52- key1 = RSAKey .generate_key ()
53- key2 = ECKey .generate_key ()
5452 obj = GeneralJSONEncryption ({"enc" : "A128CBC-HS256" }, b"i" )
55- obj .add_recipient ({"alg" : "RSA-OAEP" }, key1 )
56- obj .add_recipient ({"alg" : "ECDH-ES+A128KW" }, key2 )
53+ obj .add_recipient ({"alg" : "RSA-OAEP" }, self . rsa_key )
54+ obj .add_recipient ({"alg" : "ECDH-ES+A128KW" }, self . ec_key )
5755 value = jwe .encrypt_json (obj , None )
5856 self .assertRaises (
5957 InvalidKeyTypeError ,
6058 jwe .decrypt_json ,
61- value , key1 ,
59+ value , self . rsa_key ,
6260 )
6361 registry = jwe .JWERegistry (verify_all_recipients = False )
64- obj1 = jwe .decrypt_json (value , key1 , registry = registry )
62+ obj1 = jwe .decrypt_json (value , self . rsa_key , registry = registry )
6563 self .assertEqual (obj1 .plaintext , b"i" )
6664
6765 key3 = OctKey .generate_key ()
0 commit comments