@@ -417,6 +417,8 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
417
417
ensures version == 1 <= => ret == CSE. SIGN_ONLY
418
418
ensures version == 2 <= => ret == CSE. SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT
419
419
{
420
+ assert StructuredEncryptionHeader. ValidVersion (version);
421
+ assert version == 1 || version == 2;
420
422
if version == 2 then
421
423
CSE. SIGN_AND_INCLUDE_IN_ENCRYPTION_CONTEXT
422
424
else
@@ -546,7 +548,7 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
546
548
// get CryptoSchema for this item
547
549
function method ConfigToCryptoSchema (
548
550
config : InternalConfig ,
549
- item : ComAmazonawsDynamodbTypes .AttributeMap )
551
+ item : DynamoToStruct .TerminalDataMap )
550
552
: (ret : Result< CSE. CryptoSchemaMap, DDBE. Error> )
551
553
552
554
// = specification/dynamodb-encryption-client/encrypt-item.md#behavior
@@ -590,7 +592,7 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
590
592
// get AuthenticateSchema for this item
591
593
function method ConfigToAuthenticateSchema (
592
594
config : InternalConfig ,
593
- item : ComAmazonawsDynamodbTypes .AttributeMap )
595
+ item : DynamoToStruct .TerminalDataMap )
594
596
: (ret : CSE. AuthenticateSchemaMap)
595
597
requires ValidInternalConfig?(config)
596
598
@@ -636,6 +638,8 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
636
638
ensures ret. Success? ==> forall k < - ret. value. Keys :: InSignatureScope (config, k)
637
639
ensures ret. Success? ==> forall k < - ret. value. Keys :: ! ret. value[k]. DO_NOTHING?
638
640
{
641
+ assert forall k < - schema :: SE. IsAuthAttr (schema[k]);
642
+ assert forall k < - schema :: ! schema[k]. DO_NOTHING?;
639
643
:- Need (forall k <- schema :: InSignatureScope (config, k),
640
644
DynamoDbItemEncryptorException ( message := "Received unexpected Crypto Schema: mismatch with signature scope"));
641
645
:- Need (forall k <- schema :: ComAmazonawsDynamodbTypes .IsValid_AttributeName(k),
@@ -747,22 +751,22 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
747
751
&& (|config. structuredEncryption. History. EncryptStructure| == |old (config. structuredEncryption. History. EncryptStructure)| + 1)
748
752
&& (Seq. Last (config.structuredEncryption.History.EncryptStructure). output. Success?)
749
753
750
- // = specification/dynamodb-encryption-client/encrypt-item.md#behavior
751
- // = type=implication
752
- // # - Crypto Schema MUST be a [Crypto Schema](../structured-encryption/structures.md#crypto-schema)
753
- // # analogous to the [configured Attribute Actions](./ddb-table-encryption-config.md#attribute-actions).
754
- && ConfigToCryptoSchema (config, input.plaintextItem). Success?
755
- && Seq. Last (config.structuredEncryption.History.EncryptStructure). input. cryptoSchema
756
- == ConfigToCryptoSchema (config, input.plaintextItem). value
757
-
758
754
// = specification/dynamodb-encryption-client/encrypt-item.md#behavior
759
755
// = type=implication
760
756
// # - Structured Data MUST be the Structured Data converted above.
761
- && DynamoToStruct. ItemToStructured (input.plaintextItem). Success?
762
- && var plaintextStructure := DynamoToStruct. ItemToStructured (input.plaintextItem). value;
757
+ && DynamoToStruct. ItemToStructured2 (input.plaintextItem, config.attributeActionsOnEncrypt ). Success?
758
+ && var plaintextStructure := DynamoToStruct. ItemToStructured2 (input.plaintextItem, config.attributeActionsOnEncrypt ). value;
763
759
&& Seq. Last (config.structuredEncryption.History.EncryptStructure). input. plaintextStructure
764
760
== plaintextStructure
765
761
762
+ // = specification/dynamodb-encryption-client/encrypt-item.md#behavior
763
+ // = type=implication
764
+ // # - Crypto Schema MUST be a [Crypto Schema](../structured-encryption/structures.md#crypto-schema)
765
+ // # analogous to the [configured Attribute Actions](./ddb-table-encryption-config.md#attribute-actions).
766
+ && ConfigToCryptoSchema (config, plaintextStructure). Success?
767
+ && Seq. Last (config.structuredEncryption.History.EncryptStructure). input. cryptoSchema
768
+ == ConfigToCryptoSchema (config, plaintextStructure). value
769
+
766
770
// = specification/dynamodb-encryption-client/encrypt-item.md#behavior
767
771
// = type=implication
768
772
// # - Encryption Context MUST be this input Item's [DynamoDB Item Base Context](#dynamodb-item-base-context).
@@ -800,8 +804,6 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
800
804
==>
801
805
&& output. value. encryptedItem == input. plaintextItem
802
806
&& output. value. parsedHeader == None
803
-
804
- ensures output. Success? ==> |input. plaintextItem| <= MAX_ATTRIBUTE_COUNT
805
807
{
806
808
:- Need (
807
809
&& config.partitionKeyName in input.plaintextItem
@@ -811,12 +813,6 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
811
813
:- Need (ContextAttrsExist(config.attributeActionsOnEncrypt, input.plaintextItem),
812
814
E (ContextMissingMsg(config.attributeActionsOnEncrypt, input.plaintextItem)));
813
815
814
- if |input. plaintextItem| > MAX_ATTRIBUTE_COUNT {
815
- var actCount := String. Base10Int2String (|input.plaintextItem|);
816
- var maxCount := String. Base10Int2String (MAX_ATTRIBUTE_COUNT);
817
- return Failure (E("Item to encrypt had " + actCount + " attributes, but maximum allowed is " + maxCount));
818
- }
819
-
820
816
// = specification/dynamodb-encryption-client/encrypt-item.md#behavior
821
817
// # If a [Legacy Policy](./ddb-table-encryption-config.md#legacy-policy) of
822
818
// # `FORCE_LEGACY_ENCRYPT_ALLOW_LEGACY_DECRYPT` is specified,
@@ -839,10 +835,10 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
839
835
return Success (passthroughOutput);
840
836
}
841
837
842
- var plaintextStructure :- DynamoToStruct. ItemToStructured (input.plaintextItem)
838
+ var plaintextStructure :- DynamoToStruct. ItemToStructured2 (input.plaintextItem, config.attributeActionsOnEncrypt )
843
839
.MapFailure (e => Error.AwsCryptographyDbEncryptionSdkDynamoDb(e));
844
840
var context :- MakeEncryptionContextForEncrypt (config, plaintextStructure);
845
- var cryptoSchema :- ConfigToCryptoSchema (config, input.plaintextItem )
841
+ var cryptoSchema :- ConfigToCryptoSchema (config, plaintextStructure )
846
842
.MapFailure (e => Error.AwsCryptographyDbEncryptionSdkDynamoDb(e));
847
843
848
844
// = specification/dynamodb-encryption-client/encrypt-item.md#behavior
@@ -893,7 +889,7 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
893
889
e => Error.AwsCryptographyDbEncryptionSdkDynamoDb(DDBE.AwsCryptographyDbEncryptionSdkStructuredEncryption(e)));
894
890
var encryptedData := encryptVal. encryptedStructure;
895
891
:- Need (forall k <- encryptedData :: DDB .IsValid_AttributeName(k), E (""));
896
- var ddbKey :- DynamoToStruct. StructuredToItem (encryptedData)
892
+ var ddbKey :- DynamoToStruct. StructuredToItemEncrypt (encryptedData, input.plaintextItem, config.attributeActionsOnEncrypt )
897
893
.MapFailure (e => Error.AwsCryptographyDbEncryptionSdkDynamoDb(e));
898
894
899
895
var parsedActions :- ConvertCryptoSchemaToAttributeActions (config, encryptVal.cryptoSchema);
@@ -957,21 +953,21 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
957
953
&& (|config. structuredEncryption. History. DecryptStructure| == |old (config. structuredEncryption. History. DecryptStructure)| + 1)
958
954
&& (Seq. Last (config.structuredEncryption.History.DecryptStructure). output. Success?)
959
955
960
- // = specification/dynamodb-encryption-client/decrypt-item.md#behavior
961
- // = type=implication
962
- // # - Authenticate Schema MUST be a [Authenticate Schema](../structured-encryption/structures.md#crypto-schema)
963
- // # built with the following requirements:
964
- && Seq. Last (config.structuredEncryption.History.DecryptStructure). input. authenticateSchema
965
- == ConfigToAuthenticateSchema (config, input.encryptedItem)
966
-
967
956
// = specification/dynamodb-encryption-client/decrypt-item.md#behavior
968
957
// = type=implication
969
958
// # - Encrypted Structured Data MUST be the Structured Data converted above.
970
- && DynamoToStruct. ItemToStructured (input.encryptedItem). Success?
971
- && var plaintextStructure := DynamoToStruct. ItemToStructured (input.encryptedItem). value;
959
+ && DynamoToStruct. ItemToStructured2 (input.encryptedItem, config.attributeActionsOnEncrypt ). Success?
960
+ && var plaintextStructure := DynamoToStruct. ItemToStructured2 (input.encryptedItem, config.attributeActionsOnEncrypt ). value;
972
961
&& Seq. Last (config.structuredEncryption.History.DecryptStructure). input. encryptedStructure
973
962
== plaintextStructure
974
963
964
+ // = specification/dynamodb-encryption-client/decrypt-item.md#behavior
965
+ // = type=implication
966
+ // # - Authenticate Schema MUST be a [Authenticate Schema](../structured-encryption/structures.md#crypto-schema)
967
+ // # built with the following requirements:
968
+ && Seq. Last (config.structuredEncryption.History.DecryptStructure). input. authenticateSchema
969
+ == ConfigToAuthenticateSchema (config, plaintextStructure)
970
+
975
971
// = specification/dynamodb-encryption-client/decrypt-item.md#dynamodb-item-base-context
976
972
// = type=implication
977
973
// # The item to be encrypted MUST have an attribute named `aws_dbe_head`.
@@ -1037,13 +1033,6 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
1037
1033
&& output. value. plaintextItem == input. encryptedItem
1038
1034
&& output. value. parsedHeader == None
1039
1035
{
1040
- var realCount := |set k < - input. encryptedItem | ! (ReservedPrefix <= k)|;
1041
- if realCount > MAX_ATTRIBUTE_COUNT {
1042
- var actCount := String. Base10Int2String (realCount);
1043
- var maxCount := String. Base10Int2String (MAX_ATTRIBUTE_COUNT);
1044
- return Failure (E("Item to decrypt had " + actCount + " attributes, but maximum allowed is " + maxCount));
1045
- }
1046
-
1047
1036
:- Need (
1048
1037
&& config.partitionKeyName in input.encryptedItem
1049
1038
&& (config.sortKeyName.None? || config.sortKeyName.value in input.encryptedItem)
@@ -1081,15 +1070,15 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
1081
1070
DynamoDbItemEncryptorException (
1082
1071
message := "Encrypted item missing expected header and footer attributes"));
1083
1072
1084
- var encryptedStructure :- DynamoToStruct. ItemToStructured (input.encryptedItem)
1073
+ var encryptedStructure :- DynamoToStruct. ItemToStructured2 (input.encryptedItem, config.attributeActionsOnEncrypt )
1085
1074
.MapFailure (e => Error.AwsCryptographyDbEncryptionSdkDynamoDb(e));
1086
1075
:- Need (SE.HeaderField in input.encryptedItem, E("Header field, \"aws_dbe_head\", not in item."));
1087
1076
var header := input. encryptedItem[SE. HeaderField];
1088
1077
:- Need (header.B?, E("Header field, \"aws_dbe_head\", not binary"));
1089
1078
assert header. B?;
1090
1079
:- Need (0 < |header.B|, E("Unexpected empty header field."));
1091
1080
var context :- MakeEncryptionContextForDecrypt (config, header.B, encryptedStructure);
1092
- var authenticateSchema := ConfigToAuthenticateSchema (config, input.encryptedItem );
1081
+ var authenticateSchema := ConfigToAuthenticateSchema (config, encryptedStructure );
1093
1082
1094
1083
// = specification/dynamodb-encryption-client/decrypt-item.md#behavior
1095
1084
// # This operation MUST create a
@@ -1123,7 +1112,7 @@ module AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations refines Abs
1123
1112
e => Error.AwsCryptographyDbEncryptionSdkDynamoDb(DDBE.AwsCryptographyDbEncryptionSdkStructuredEncryption(e)));
1124
1113
var decryptedData := decryptVal. plaintextStructure;
1125
1114
:- Need (forall k <- decryptedData :: DDB .IsValid_AttributeName(k), E (""));
1126
- var ddbItem :- DynamoToStruct. StructuredToItem (decryptedData)
1115
+ var ddbItem :- DynamoToStruct. StructuredToItemDecrypt (decryptedData, input.encryptedItem, decryptVal.cryptoSchema )
1127
1116
.MapFailure (e => Error.AwsCryptographyDbEncryptionSdkDynamoDb(e));
1128
1117
1129
1118
var schemaToConvert := decryptVal. cryptoSchema;
0 commit comments