@@ -290,6 +290,40 @@ def scenario_spec(self):
290290 return spec
291291
292292
293+ class TestVectorsMultiMasterKeyProvider (MasterKeyProvider ):
294+ """
295+ Provider for other MasterKeyProviders.
296+ Acts as a "multi" MasterKeyProvider for use in test vectors.
297+
298+ There is some disagreement between the spec
299+ and how Python ESDK implements MasterKey;
300+ this class fills that gap.
301+
302+ In the ESDK-Python, MasterKey extends MasterKeyProvider;
303+ i.e. MasterKey "is a" MasterKeyProvider; isinstance(some_master_key, MasterKeyProvider) == True.
304+
305+ However, MasterKey overrides MasterKeyProvider's `decrypt_data_key` method.
306+ From AWS ESDK specification:
307+ "A master key MUST supply itself and MUST NOT supply any other master keys."
308+ https://github.com/awslabs/aws-encryption-sdk-specification/blob/master/framework/master-key-interface.md#get-master-key
309+
310+ This suggests that this "is a" relationship is not entirely true.
311+
312+ master_key_provider_from_master_key_specs uses this class to provide all loaded MasterKeyProviders (or MasterKeys)
313+ from an interface that supports supplying other master keys.
314+ """
315+
316+ _config_class = MasterKeyProviderConfig
317+ provider_id = "aws-test-vectors-multi-master-key-provider"
318+
319+ def add_key (self , key_provider ):
320+ self ._members .append (key_provider )
321+
322+ def _new_master_key (self , key_id ):
323+ # This MKP does not have a key associated with it.
324+ raise InvalidKeyIdError ()
325+
326+
293327def master_key_provider_from_master_key_specs (keys , master_key_specs ):
294328 # type: (KeysManifest, Iterable[MasterKeySpec]) -> MasterKeyProvider
295329 """Build and combine all master key providers identified by the provided specs and
@@ -302,8 +336,7 @@ def master_key_provider_from_master_key_specs(keys, master_key_specs):
302336 :rtype: MasterKeyProvider
303337 """
304338 master_keys = [spec .master_key (keys ) for spec in master_key_specs ]
305- primary = master_keys [0 ]
306- others = master_keys [1 :]
307- for master_key in others :
308- primary .add_master_key_provider (master_key )
309- return primary
339+ mkp = TestVectorsMultiMasterKeyProvider ()
340+ for master_key in master_keys :
341+ mkp .add_key (master_key )
342+ return mkp
0 commit comments