Skip to content

Commit 6e6fd6b

Browse files
format code
1 parent dda196a commit 6e6fd6b

File tree

2 files changed

+315
-315
lines changed

2 files changed

+315
-315
lines changed

DynamoDbEncryption/dafny/DynamoDbEncryption/src/AwsCryptographyDbEncryptionSdkDynamoDbOperations.dfy

+25-25
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module AwsCryptographyDbEncryptionSdkDynamoDbOperations refines AbstractAwsCrypt
2020
{ {} }
2121

2222
datatype Config = Config(
23-
)
23+
)
2424

2525
type InternalConfig = Config
2626

@@ -32,33 +32,33 @@ module AwsCryptographyDbEncryptionSdkDynamoDbOperations refines AbstractAwsCrypt
3232
input: CreateDynamoDbEncryptionBranchKeyIdSupplierInput
3333
) returns (output: Result<CreateDynamoDbEncryptionBranchKeyIdSupplierOutput, Error>) {
3434
var supplier := new DynamoDbEncryptionBranchKeyIdSupplier.DynamoDbEncryptionBranchKeyIdSupplier(
35-
input.ddbKeyBranchKeyIdSupplier
35+
input.ddbKeyBranchKeyIdSupplier
3636
);
3737
return Success(
3838
CreateDynamoDbEncryptionBranchKeyIdSupplierOutput(
3939
branchKeyIdSupplier := supplier
4040
)
41-
);
41+
);
4242
}
4343
predicate GetEncryptedDataKeyDescriptionEnsuresPublicly(input: GetEncryptedDataKeyDescriptionInput , output: Result<GetEncryptedDataKeyDescriptionOutput, Error>)
4444
{true}
4545

4646
method GetEncryptedDataKeyDescription(config: InternalConfig, input: GetEncryptedDataKeyDescriptionInput)
4747
returns (output: Result<GetEncryptedDataKeyDescriptionOutput, Error>)
4848
ensures GetEncryptedDataKeyDescriptionEnsuresPublicly(input, output)
49-
ensures output.Success? ==> (
50-
match input.input {
51-
case plaintextItem(item) =>
52-
DynamoToStruct.ItemToStructured(item).Success?
53-
&& var extracted := DynamoToStruct.ItemToStructured(item).Extract();
54-
&& var keys := extracted.Keys;
55-
&& "aws_dbe_head" in DynamoToStruct.ItemToStructured(item).Extract()
56-
&& var header := DynamoToStruct.ItemToStructured(item).Extract()["aws_dbe_head"].content.Terminal.value;
57-
&& Header.PartialDeserialize(header).Success?
58-
case header(header) =>
59-
Header.PartialDeserialize(header).Success?
60-
}
61-
)
49+
ensures output.Success? ==> (
50+
match input.input {
51+
case plaintextItem(item) =>
52+
DynamoToStruct.ItemToStructured(item).Success?
53+
&& var extracted := DynamoToStruct.ItemToStructured(item).Extract();
54+
&& var keys := extracted.Keys;
55+
&& "aws_dbe_head" in DynamoToStruct.ItemToStructured(item).Extract()
56+
&& var header := DynamoToStruct.ItemToStructured(item).Extract()["aws_dbe_head"].content.Terminal.value;
57+
&& Header.PartialDeserialize(header).Success?
58+
case header(header) =>
59+
Header.PartialDeserialize(header).Success?
60+
}
61+
)
6262
{
6363
var header;
6464
match input.input
@@ -74,7 +74,7 @@ module AwsCryptographyDbEncryptionSdkDynamoDbOperations refines AbstractAwsCrypt
7474
:- Need(Header.PartialDeserialize(header).Success?, E("Failed to deserialize header."));
7575
var deserializedHeader := Header.PartialDeserialize(header);
7676
var algorithmSuite;
77-
77+
7878
if deserializedHeader.Extract().flavor == 0{
7979
algorithmSuite := AlgorithmSuites.DBE_ALG_AES_256_GCM_HKDF_SHA512_COMMIT_KEY_SYMSIG_HMAC_SHA384;
8080
} else {
@@ -85,7 +85,7 @@ module AwsCryptographyDbEncryptionSdkDynamoDbOperations refines AbstractAwsCrypt
8585
var list : EncryptedDataKeyDescriptionList := [];
8686
for i := 0 to |datakeys| {
8787
var singleDataKeyOutput : EncryptedDataKeyDescriptionOutput;
88-
88+
8989
:- Need(UTF8.Decode(datakeys[i].keyProviderId).Success?, E("Failed to extract keyProviderId."));
9090
:- Need(UTF8.Decode(datakeys[i].keyProviderInfo).Success?, E("Failed to extract keyProviderInfo."));
9191

@@ -95,48 +95,48 @@ module AwsCryptographyDbEncryptionSdkDynamoDbOperations refines AbstractAwsCrypt
9595
if |extractedKeyProviderId| < 7 || extractedKeyProviderId[0..7] != "aws-kms" {
9696
singleDataKeyOutput := EncryptedDataKeyDescriptionOutput(
9797
keyProviderId := extractedKeyProviderId,
98-
keyProviderInfo := None,
98+
keyProviderInfo := None,
9999
branchKeyId := None,
100100
branchKeyVersion := None
101101
);
102102
}
103103
if extractedKeyProviderId == "aws-kms-hierarchy" {
104104
:- Need(EdkWrapping.GetProviderWrappedMaterial(datakeys[i].ciphertext, algorithmSuite).Success?, E("Failed to get provider wrapped material."));
105-
105+
106106
var providerWrappedMaterial := EdkWrapping.GetProviderWrappedMaterial(datakeys[i].ciphertext, algorithmSuite).Extract();
107107

108108
// The ciphertext structure in the hierarchy keyring contains Salt and IV before Version.
109109
// The length of Salt is 16 and IV is 12 bytes. The length of Version is 16 bytes.
110110
// https://github.com/awslabs/aws-encryption-sdk-specification/blob/master/framework/aws-kms/aws-kms-hierarchical-keyring.md#ciphertext
111-
111+
112112
var EDK_CIPHERTEXT_BRANCH_KEY_VERSION_INDEX := 12 + 16;
113113
var EDK_CIPHERTEXT_VERSION_INDEX := EDK_CIPHERTEXT_BRANCH_KEY_VERSION_INDEX + 16;
114114

115115
:- Need(EDK_CIPHERTEXT_BRANCH_KEY_VERSION_INDEX < EDK_CIPHERTEXT_VERSION_INDEX, E("Wrong branch key version index."));
116116
:- Need(|providerWrappedMaterial| >= EDK_CIPHERTEXT_VERSION_INDEX, E("Incorrect ciphertext structure length."));
117117
var branchKeyVersionUuid := providerWrappedMaterial[EDK_CIPHERTEXT_BRANCH_KEY_VERSION_INDEX .. EDK_CIPHERTEXT_VERSION_INDEX];
118-
118+
119119
:- Need(UUID.FromByteArray(branchKeyVersionUuid).Success?, E("Failed to convert UUID from byte array."));
120120
var expectedBranchKeyVersion := UUID.FromByteArray(branchKeyVersionUuid).Extract();
121121

122122
singleDataKeyOutput := EncryptedDataKeyDescriptionOutput(
123123
keyProviderId := extractedKeyProviderId,
124-
keyProviderInfo := Some(extractedKeyProviderIdInfo),
124+
keyProviderInfo := Some(extractedKeyProviderIdInfo),
125125
branchKeyId := Some(extractedKeyProviderIdInfo),
126126
branchKeyVersion := Some(expectedBranchKeyVersion)
127127
);
128128
}
129129
else {
130130
singleDataKeyOutput := EncryptedDataKeyDescriptionOutput(
131131
keyProviderId := extractedKeyProviderId,
132-
keyProviderInfo := Some(extractedKeyProviderIdInfo),
132+
keyProviderInfo := Some(extractedKeyProviderIdInfo),
133133
branchKeyId := None,
134134
branchKeyVersion := None
135135
);
136136
}
137137
list := list + [singleDataKeyOutput];
138138
}
139-
139+
140140
output := Success(GetEncryptedDataKeyDescriptionOutput(
141141
EncryptedDataKeyDescriptionOutput := list
142142
));

0 commit comments

Comments
 (0)