@@ -25,6 +25,8 @@ module {:options "/functionSyntax:4" } Structure {
25
25
const M_INPUT := "input" // The DDB Attribute name for the input, which is AttributeValue.B
26
26
const M_UUID := "uuid" // The DDB Attribute name for the uuid, which is AttributeValue.S
27
27
const M_PAGE_INDEX := "pageIndex" // The DDB Attribute name for the pageIndex, which is AttributeValue.B
28
+ const HIERARCHY_VERSION_1 := "1"
29
+ const HIERARCHY_VERSION_2 := "2"
28
30
29
31
const AWS_CRYPTO_EC := "aws- crypto- ec"
30
32
const ENCRYPTION_CONTEXT_PREFIX := AWS_CRYPTO_EC + ":"
@@ -186,7 +188,20 @@ module {:options "/functionSyntax:4" } Structure {
186
188
requires BranchKeyItem?(item)
187
189
ensures EncryptedHierarchicalKey?(output)
188
190
{
189
- var EncryptionContext := map k < - item. Keys - {BRANCH_KEY_FIELD} + {TABLE_FIELD}
191
+ var EncryptionContext := if item[HIERARCHY_VERSION]. N == HIERARCHY_VERSION_1
192
+ then GetEncryptionContextHV1 (item, logicalKeyStoreName)
193
+ else GetEncryptionContextHV2 (item);
194
+
195
+ ConstructEncryptedHierarchicalKey (EncryptionContext, item[BRANCH_KEY_FIELD].B)
196
+ }
197
+
198
+ function GetEncryptionContextHV1 (
199
+ item: DDB .AttributeMap,
200
+ logicalKeyStoreName: string
201
+ ): (output: map < string , string > )
202
+ requires BranchKeyItem?(item)
203
+ {
204
+ map k < - item. Keys - {BRANCH_KEY_FIELD} + {TABLE_FIELD}
190
205
// Working around https://github.com/dafny-lang/dafny/issues/5776
191
206
// that will make the following fail to compile
192
207
// match k
@@ -198,9 +213,26 @@ module {:options "/functionSyntax:4" } Structure {
198
213
else if k == TABLE_FIELD then
199
214
logicalKeyStoreName
200
215
else
201
- item[k]. S;
216
+ item[k]. S
217
+ }
202
218
203
- ConstructEncryptedHierarchicalKey (EncryptionContext, item[BRANCH_KEY_FIELD].B)
219
+ function GetEncryptionContextHV2 (
220
+ item: DDB .AttributeMap
221
+ ): (output: map < string , string > )
222
+ requires BranchKeyItem?(item)
223
+ {
224
+ var fieldsToRemove := {
225
+ BRANCH_KEY_FIELD,
226
+ BRANCH_KEY_IDENTIFIER_FIELD,
227
+ TYPE_FIELD,
228
+ KEY_CREATE_TIME,
229
+ HIERARCHY_VERSION,
230
+ KMS_FIELD,
231
+ BRANCH_KEY_ACTIVE_VERSION_FIELD
232
+ };
233
+
234
+ map k < - item. Keys - fieldsToRemove
235
+ :: k[|ENCRYPTION_CONTEXT_PREFIX|.. ] := item[k]. S
204
236
}
205
237
206
238
function ConstructEncryptedHierarchicalKey (
0 commit comments