81
81
# We only actually need these imports when running the mypy checks
82
82
pass
83
83
84
- SUPPORTED_VERSIONS = (2 ,)
84
+ SUPPORTED_VERSIONS = (2 , 4 , )
85
85
86
86
87
87
class TamperingMethod :
@@ -410,6 +410,8 @@ class MessageDecryptionTestScenarioGenerator(object):
410
410
decryption_master_key_provider_fn = attr .ib (validator = attr .validators .is_callable ())
411
411
result = attr .ib (validator = attr .validators .optional (attr .validators .instance_of (MessageDecryptionTestResult )))
412
412
keyrings = attr .ib (validator = attr .validators .instance_of (bool ))
413
+ cmm_type = attr .ib (validator = attr .validators .optional (attr .validators .instance_of (str )))
414
+ encryption_context = attr .ib (validator = attr .validators .optional (attr .validators .instance_of (dict )))
413
415
414
416
@classmethod
415
417
def from_scenario (cls , scenario , keys , plaintexts , keyrings , keys_uri ):
@@ -432,6 +434,10 @@ def from_scenario(cls, scenario, keys, plaintexts, keyrings, keys_uri):
432
434
keyrings ,
433
435
keys_uri ,
434
436
)
437
+
438
+ if encryption_scenario is None :
439
+ return None
440
+
435
441
tampering = scenario .get ("tampering" )
436
442
tampering_method = TamperingMethod .from_tampering_spec (tampering )
437
443
decryption_method_spec = scenario .get ("decryption-method" )
@@ -457,6 +463,16 @@ def decryption_master_key_provider_fn():
457
463
result_spec = scenario .get ("result" )
458
464
result = MessageDecryptionTestResult .from_result_spec (result_spec , None ) if result_spec else None
459
465
466
+ try :
467
+ encryption_context = encryption_scenario_spec ["encryption-context" ]
468
+ except KeyError :
469
+ encryption_context = None
470
+
471
+ try :
472
+ cmm_type = encryption_scenario_spec ["cmm" ]
473
+ except KeyError :
474
+ cmm_type = None
475
+
460
476
return cls (
461
477
encryption_scenario = encryption_scenario ,
462
478
tampering_method = tampering_method ,
@@ -465,6 +481,8 @@ def decryption_master_key_provider_fn():
465
481
decryption_master_key_provider_fn = decryption_master_key_provider_fn ,
466
482
result = result ,
467
483
keyrings = keyrings ,
484
+ cmm_type = cmm_type ,
485
+ encryption_context = encryption_context ,
468
486
)
469
487
470
488
def run (self , ciphertext_writer , plaintext_uri ):
@@ -494,8 +512,8 @@ def decryption_test_scenario_pair(self, ciphertext_writer, ciphertext_to_decrypt
494
512
decryption_method = self .decryption_method ,
495
513
result = expected_result ,
496
514
keyrings = self .keyrings ,
497
- cmm_type = "Default" ,
498
- encryption_context = {}
515
+ cmm_type = self . cmm_type ,
516
+ encryption_context = self . encryption_context ,
499
517
),
500
518
)
501
519
@@ -533,6 +551,7 @@ def _generate_plaintexts(plaintexts_specs):
533
551
534
552
@classmethod
535
553
def from_file (cls , input_file , keyrings ):
554
+ # pylint: disable=too-many-locals
536
555
# type: (IO) -> MessageDecryptionGenerationManifest
537
556
"""Load from a file containing a full message encrypt manifest.
538
557
0 commit comments