in src/aws_encryption_sdk/materials_managers/default.py [0:0]
def get_encryption_materials(self, request):
"""Creates encryption materials using underlying master key provider.
:param request: encryption materials request
:type request: aws_encryption_sdk.materials_managers.EncryptionMaterialsRequest
:returns: encryption materials
:rtype: aws_encryption_sdk.materials_managers.EncryptionMaterials
:raises MasterKeyProviderError: if no master keys are available from the underlying master key provider
:raises MasterKeyProviderError: if the primary master key provided by the underlying master key provider
is not included in the full set of master keys provided by that provider
:raises ActionNotAllowedError: if the commitment policy in the request is violated by the algorithm being
used
"""
default_algorithm = ALGORITHM
if request.commitment_policy in (
CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT,
CommitmentPolicy.REQUIRE_ENCRYPT_ALLOW_DECRYPT,
):
default_algorithm = ALGORITHM_COMMIT_KEY
algorithm = request.algorithm if request.algorithm is not None else default_algorithm
validate_commitment_policy_on_encrypt(request.commitment_policy, request.algorithm)
encryption_context = request.encryption_context.copy()
signing_key = self._generate_signing_key_and_update_encryption_context(algorithm, encryption_context)
primary_master_key, master_keys = self.master_key_provider.master_keys_for_encryption(
encryption_context=encryption_context,
plaintext_rostream=request.plaintext_rostream,
plaintext_length=request.plaintext_length,
)
if not master_keys:
raise MasterKeyProviderError("No Master Keys available from Master Key Provider")
if primary_master_key not in master_keys:
raise MasterKeyProviderError("Primary Master Key not in provided Master Keys")
data_encryption_key, encrypted_data_keys = prepare_data_keys(
primary_master_key=primary_master_key,
master_keys=master_keys,
algorithm=algorithm,
encryption_context=encryption_context,
)
_LOGGER.debug("Post-encrypt encryption context: %s", encryption_context)
return EncryptionMaterials(
algorithm=algorithm,
data_encryption_key=data_encryption_key,
encrypted_data_keys=encrypted_data_keys,
encryption_context=encryption_context,
signing_key=signing_key,
)