@@ -10,7 +10,7 @@ module QueryTransform {
1010 import DDB = ComAmazonawsDynamodbTypes
1111 import opened AwsCryptographyDbEncryptionSdkDynamoDbTransformsTypes
1212 import EncTypes = AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorTypes
13- import Seq
13+ import EncOps = AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations
1414
1515 method Input (config: Config , input: QueryInputTransformInput )
1616 returns (output: Result< QueryInputTransformOutput, Error> )
@@ -90,10 +90,19 @@ module QueryTransform {
9090 // # with the resulting decrypted [DynamoDB Item](./decrypt-item.md#dynamodb-item-1).
9191 var decryptInput := EncTypes. DecryptItemInput (encryptedItem := encryptedItems[x]);
9292 var decryptRes := tableConfig. itemEncryptor. DecryptItem (decryptInput);
93-
9493 var decrypted :- MapError (decryptRes);
95- if keyId. KeyId? {
96- :- Need (decrypted.parsedHeader.Some?, E("Decrypted query result has no parsed header."));
94+
95+ // If the decrypted result was plaintext, i.e. has no parsedHeader
96+ // then this is expected IFF the table config allows plaintext read
97+ assert decrypted. parsedHeader. None? ==>
98+ && EncOps. IsPlaintextItem (encryptedItems[x])
99+ && ! tableConfig. plaintextOverride. FORBID_PLAINTEXT_WRITE_FORBID_PLAINTEXT_READ?
100+ && (
101+ || tableConfig. plaintextOverride. FORBID_PLAINTEXT_WRITE_ALLOW_PLAINTEXT_READ?
102+ || tableConfig. plaintextOverride. FORCE_PLAINTEXT_WRITE_ALLOW_PLAINTEXT_READ?
103+ );
104+
105+ if keyId. KeyId? && decrypted. parsedHeader. Some? {
97106 :- Need (|decrypted.parsedHeader.value.encryptedDataKeys| == 1, E("Query result has more than one Encrypted Data Key"));
98107 if decrypted. parsedHeader. value. encryptedDataKeys[0]. keyProviderInfo == keyIdUtf8 {
99108 decryptedItems := decryptedItems + [decrypted. plaintextItem];
0 commit comments