Skip to content

Commit 310b9b8

Browse files
guard native cx
1 parent 5c1b77e commit 310b9b8

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/aws_encryption_sdk/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def decrypt(self, **kwargs):
186186
to the end of the stream and tell() to find the length of source data.
187187
188188
:param dict encryption_context: Dictionary defining encryption context to validate
189-
on decrypt.
189+
on decrypt. This is ONLY validated on decrypt if using a CMM from the
190+
aws-cryptographic-material-providers library.
190191
:param int max_body_length: Maximum frame size (or content length for non-framed messages)
191192
in bytes to read from ciphertext message.
192193
:returns: Tuple containing the decrypted plaintext and the message header object

src/aws_encryption_sdk/streaming_client.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -963,13 +963,18 @@ def _create_decrypt_materials_request(self, header):
963963
# If encryption_context is provided on decrypt,
964964
# pass it to the DecryptionMaterialsRequest as reproduced_encryption_context
965965
if hasattr(self.config, "encryption_context"):
966-
return DecryptionMaterialsRequest(
967-
encrypted_data_keys=header.encrypted_data_keys,
968-
algorithm=header.algorithm,
969-
encryption_context=header.encryption_context,
970-
commitment_policy=self.config.commitment_policy,
971-
reproduced_encryption_context=self.config.encryption_context
972-
)
966+
if (_HAS_MPL
967+
and isinstance(self.config.materials_manager, CryptoMaterialsManagerFromMPL)):
968+
return DecryptionMaterialsRequest(
969+
encrypted_data_keys=header.encrypted_data_keys,
970+
algorithm=header.algorithm,
971+
encryption_context=header.encryption_context,
972+
commitment_policy=self.config.commitment_policy,
973+
reproduced_encryption_context=self.config.encryption_context
974+
)
975+
else:
976+
raise TypeError("encryption_context on decrypt is only supported for CMMs and keyrings "\
977+
"from the aws-cryptographic-material-providers library.")
973978
return DecryptionMaterialsRequest(
974979
encrypted_data_keys=header.encrypted_data_keys,
975980
algorithm=header.algorithm,

0 commit comments

Comments
 (0)