@@ -10,7 +10,7 @@ module QueryTransform {
10
10
import DDB = ComAmazonawsDynamodbTypes
11
11
import opened AwsCryptographyDbEncryptionSdkDynamoDbTransformsTypes
12
12
import EncTypes = AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorTypes
13
- import Seq
13
+ import EncOps = AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations
14
14
15
15
method Input (config: Config , input: QueryInputTransformInput )
16
16
returns (output: Result< QueryInputTransformOutput, Error> )
@@ -90,10 +90,19 @@ module QueryTransform {
90
90
// # with the resulting decrypted [DynamoDB Item](./decrypt-item.md#dynamodb-item-1).
91
91
var decryptInput := EncTypes. DecryptItemInput (encryptedItem := encryptedItems[x]);
92
92
var decryptRes := tableConfig. itemEncryptor. DecryptItem (decryptInput);
93
-
94
93
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? {
97
106
:- Need (|decrypted.parsedHeader.value.encryptedDataKeys| == 1, E("Query result has more than one Encrypted Data Key"));
98
107
if decrypted. parsedHeader. value. encryptedDataKeys[0]. keyProviderInfo == keyIdUtf8 {
99
108
decryptedItems := decryptedItems + [decrypted. plaintextItem];
0 commit comments