Skip to content

Commit 4d86007

Browse files
authored
feat: add virtual fields (#66)
* feat: add virtual fields * add config parsing * config conversion
1 parent a102cd7 commit 4d86007

File tree

21 files changed

+1853
-146
lines changed

21 files changed

+1853
-146
lines changed

DynamoDbEncryptionMiddlewareInternal/src/DDBSupport.dfy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module DynamoDBMiddlewareSupport {
1818
import opened StandardLibrary.UInt
1919
import opened BS = DynamoDBSupport
2020
import opened DdbMiddlewareConfig
21+
import AwsCryptographyDynamoDbItemEncryptorOperations
2122

2223
// IsWritable examines an AttributeMap and fails if it is unsuitable for writing.
2324
// Generally this means that no attribute names starts with "aws_dbe_"
@@ -62,6 +63,7 @@ module DynamoDBMiddlewareSupport {
6263
// returning a replacement AttributeMap.
6364
function method {:opaque} AddBeacons(config : ValidTableConfig, item : DDB.AttributeMap)
6465
: Result<DDB.AttributeMap, Error>
66+
requires AwsCryptographyDynamoDbItemEncryptorOperations.ValidInternalConfig?(config.itemEncryptor.config)
6567
{
6668
BS.AddBeacons(config.itemEncryptor.config, item)
6769
.MapFailure(e => E(e))

DynamoDbEncryptionMiddlewareInternal/src/TransactWriteItemsTransform.dfy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ module TransactWriteItemsTransform {
2828
ensures output.Success? ==> |output.value.transformedInput.TransactItems| == |input.sdkInput.TransactItems|
2929

3030
//= specification/dynamodb-encryption-client/ddb-sdk-integration.md#encrypt-before-transactwriteitems
31-
//= type=implication
3231
//# To protect against a possible fifth field being added to the TransactWriteItem structure in the future,
3332
//# the client MUST fail if none of the `Update`, `ConditionCheck`, `Delete` and `Put` fields are set.
3433
ensures output.Success? ==>
3534
forall item <- input.sdkInput.TransactItems :: IsValid(item)
3635
{
37-
:- Need(forall item <- input.sdkInput.TransactItems :: IsValid(item), E("Each item in TransactWriteItems must specify at least one operation"));
36+
:- Need(forall item <- input.sdkInput.TransactItems :: IsValid(item), E("Each item in TransactWriteItems must specify at least one supported operation"));
3837
var result : seq<DDB.TransactWriteItem> := [];
3938
for x := 0 to |input.sdkInput.TransactItems|
4039
invariant |result| == x
@@ -110,7 +109,8 @@ module TransactWriteItemsTransform {
110109
//# the result [Encrypted DynamoDB Item](./encrypt-item.md#encrypted-dynamodb-item)
111110
//# calculated above.
112111
var put := Some(item.Put.value.(Item := encrypted.encryptedItem));
113-
result := result + [item.(Put := put)];
112+
var newItem := item.(Put := put);
113+
result := result + [newItem];
114114
} else {
115115
//= specification/dynamodb-encryption-client/ddb-sdk-integration.md#encrypt-before-transactwriteitems
116116
//# Any actions other than `Put, MUST be unchanged.

DynamoDbEncryptionMiddlewareInternal/test/TransactWriteItemsTransform.dfy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module TransactWriteItemsTransformTest {
6161
sdkInput := input
6262
)
6363
);
64-
ExpectFailure(transformed, "Each item in TransactWriteItems must specify at least one operation");
64+
ExpectFailure(transformed, "Each item in TransactWriteItems must specify at least one supported operation");
6565
}
6666

6767
method {:test} TestTransactWriteItemsOutputTransform() {

DynamoDbItemEncryptor/src/AwsCryptographyDynamoDbItemEncryptorOperations.dfy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
include "../Model/AwsCryptographyDynamoDbItemEncryptorTypes.dfy"
44
include "../../private-aws-encryption-sdk-dafny-staging/AwsCryptographicMaterialProviders/src/CMMs/ExpectedEncryptionContextCMM.dfy"
55
include "DynamoToStruct.dfy"
6+
include "../../StructuredEncryption/src/SearchInfo.dfy"
67

78
module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptographyDynamoDbItemEncryptorOperations {
89
import opened StructuredEncryptionUtil
@@ -18,6 +19,7 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
1819
import SE = StructuredEncryptionUtil
1920
import MaterialProviders
2021
import ExpectedEncryptionContextCMM
22+
import opened SearchableEncryptionInfo
2123

2224
datatype Config = Config(
2325
nameonly cmpClient : MaterialProviders.MaterialProvidersClient,
@@ -29,7 +31,8 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
2931
nameonly allowedUnauthenticatedAttributes: Option<ComAmazonawsDynamodbTypes.AttributeNameList>,
3032
nameonly allowedUnauthenticatedAttributePrefix: Option<string>,
3133
nameonly algorithmSuiteId: Option<CMP.DBEAlgorithmSuiteId>,
32-
nameonly structuredEncryption: StructuredEncryption.StructuredEncryptionClient
34+
nameonly structuredEncryption: StructuredEncryption.StructuredEncryptionClient,
35+
nameonly beacons : Option<SearchInfo>
3336
// TODO legacy encryptor
3437
// TODO legacy schema
3538
)
@@ -266,6 +269,7 @@ module AwsCryptographyDynamoDbItemEncryptorOperations refines AbstractAwsCryptog
266269
&& (forall attribute <- config.attributeActions.Keys ::
267270
!(SE.ReservedPrefix <= attribute))
268271

272+
&& (config.beacons.Some? ==> config.beacons.value.ValidState())
269273
}
270274

271275
function ModifiesInternalConfig(config: InternalConfig) : set<object>

0 commit comments

Comments
 (0)