Skip to content

Commit 23b5de7

Browse files
Add getBranchKeyVersion to decrease resource count
1 parent 9deae04 commit 23b5de7

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

DynamoDbEncryption/dafny/DynamoDbEncryption/test/DynamoDbGetEncryptedDataKeyDescriptionTest.dfy

+19-15
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ module DynamoDbGetEncryptedDataKeyDescriptionTest {
104104
var expectedHead := CreatePartialHeader(testVersion, testFlavor, testMsgID, testLegend, testEncContext, [testAwsKmsHDataKey]);
105105
var serializedHeader := expectedHead.serialize() + expectedHead.msgID;
106106

107-
expect EdkWrapping.GetProviderWrappedMaterial(expectedHead.dataKeys[0].ciphertext, algorithmSuite).Success?;
108-
var providerWrappedMaterial := EdkWrapping.GetProviderWrappedMaterial(expectedHead.dataKeys[0].ciphertext, algorithmSuite).Extract();
109-
expect |providerWrappedMaterial| >= (16 + 12 + 16);
110-
var expectedBranchKeyVersionUuid := UUID.FromByteArray(providerWrappedMaterial[16 + 12 .. (16 + 12 + 16)]);
107+
var expectedBranchKeyVersion := getBranchKeyVersion(expectedHead);
111108
var ddbEncResources :- expect DynamoDbEncryption.DynamoDbEncryption();
112109

113110
var inputVariable: Types.GetEncryptedDataKeyDescriptionInput :=
@@ -117,7 +114,6 @@ module DynamoDbGetEncryptedDataKeyDescriptionTest {
117114

118115
var actualDataKeyDescription := ddbEncResources.GetEncryptedDataKeyDescription(inputVariable);
119116

120-
expect expectedBranchKeyVersionUuid.Success?;
121117
expect UTF8.Decode(expectedHead.dataKeys[0].keyProviderId).Success?;
122118
expect UTF8.Decode(expectedHead.dataKeys[0].keyProviderInfo).Success?;
123119
expect actualDataKeyDescription.Success?;
@@ -134,7 +130,7 @@ module DynamoDbGetEncryptedDataKeyDescriptionTest {
134130
expect actualDataKeyDescription.Extract().EncryptedDataKeyDescriptionOutput[0].branchKeyVersion.Some?;
135131

136132
expect actualDataKeyDescription.Extract().EncryptedDataKeyDescriptionOutput[0].branchKeyId.Extract() == UTF8.Decode(expectedHead.dataKeys[0].keyProviderInfo).Extract();
137-
expect actualDataKeyDescription.Extract().EncryptedDataKeyDescriptionOutput[0].branchKeyVersion.Extract() == expectedBranchKeyVersionUuid.Extract();
133+
expect actualDataKeyDescription.Extract().EncryptedDataKeyDescriptionOutput[0].branchKeyVersion.Extract() == expectedBranchKeyVersion;
138134
}
139135
}
140136

@@ -223,24 +219,17 @@ module DynamoDbGetEncryptedDataKeyDescriptionTest {
223219
var expectedHead := CreatePartialHeader(testVersion, testFlavor, testMsgID, testLegend, testEncContext, [testAwsKmsHDataKey]);
224220
var serializedHeader := expectedHead.serialize() + expectedHead.msgID;
225221

226-
expect EdkWrapping.GetProviderWrappedMaterial(expectedHead.dataKeys[0].ciphertext, algorithmSuite).Success?;
227-
var providerWrappedMaterial := EdkWrapping.GetProviderWrappedMaterial(expectedHead.dataKeys[0].ciphertext, algorithmSuite).Extract();
228-
229-
expect |providerWrappedMaterial| >= (28 + 16);
230-
231-
var expectedBranchKeyVersionUuid := UUID.FromByteArray(providerWrappedMaterial[28 .. (28 + 16)]);
222+
var expectedBranchKeyVersion := getBranchKeyVersion(expectedHead);
232223
var attr := map["aws_dbe_head" := ComAmazonawsDynamodbTypes.AttributeValue.B(serializedHeader)];
233224
var ddbEncResources :- expect DynamoDbEncryption.DynamoDbEncryption();
234225

235-
236226
var inputVariable: Types.GetEncryptedDataKeyDescriptionInput :=
237227
Types.GetEncryptedDataKeyDescriptionInput(
238228
input := Types.plaintextItem(plaintextItem := attr)
239229
);
240230

241231
var actualDataKeyDescription := ddbEncResources.GetEncryptedDataKeyDescription(inputVariable);
242232

243-
expect expectedBranchKeyVersionUuid.Success?;
244233
expect UTF8.Decode(expectedHead.dataKeys[0].keyProviderId).Success?;
245234
expect UTF8.Decode(expectedHead.dataKeys[0].keyProviderInfo).Success?;
246235
expect actualDataKeyDescription.Success?;
@@ -257,7 +246,7 @@ module DynamoDbGetEncryptedDataKeyDescriptionTest {
257246
expect actualDataKeyDescription.Extract().EncryptedDataKeyDescriptionOutput[0].branchKeyVersion.Some?;
258247

259248
expect actualDataKeyDescription.Extract().EncryptedDataKeyDescriptionOutput[0].branchKeyId.Extract() == UTF8.Decode(expectedHead.dataKeys[0].keyProviderInfo).Extract();
260-
expect actualDataKeyDescription.Extract().EncryptedDataKeyDescriptionOutput[0].branchKeyVersion.Extract() == expectedBranchKeyVersionUuid.Extract();
249+
expect actualDataKeyDescription.Extract().EncryptedDataKeyDescriptionOutput[0].branchKeyVersion.Extract() == expectedBranchKeyVersion;
261250
}
262251
}
263252

@@ -316,4 +305,19 @@ module DynamoDbGetEncryptedDataKeyDescriptionTest {
316305
expect actualDataKeyDescription.Extract().EncryptedDataKeyDescriptionOutput[0].keyProviderInfo.Some?;
317306
expect actualDataKeyDescription.Extract().EncryptedDataKeyDescriptionOutput[0].keyProviderInfo.Extract() == UTF8.Decode(expectedHead.dataKeys[0].keyProviderInfo).Extract();
318307
}
308+
309+
method getBranchKeyVersion (expectedHead : PartialHeader)
310+
returns (expectedBranchKeyVersion : string)
311+
{
312+
expect EdkWrapping.GetProviderWrappedMaterial(expectedHead.dataKeys[0].ciphertext, algorithmSuite).Success?;
313+
var providerWrappedMaterial := EdkWrapping.GetProviderWrappedMaterial(expectedHead.dataKeys[0].ciphertext, algorithmSuite).Extract();
314+
315+
expect |providerWrappedMaterial| >= (28 + 16);
316+
317+
var expectedBranchKeyVersionResult := UUID.FromByteArray(providerWrappedMaterial[28 .. (28 + 16)]);
318+
319+
expect expectedBranchKeyVersionResult.Success?;
320+
321+
expectedBranchKeyVersion := expectedBranchKeyVersionResult.Extract();
322+
}
319323
}

0 commit comments

Comments
 (0)