Skip to content

Commit 082c1ff

Browse files
committed
WIP
1 parent f7e0513 commit 082c1ff

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

AwsCryptographicMaterialProviders/dafny/AwsCryptographyKeyStore/src/HierarchicalVersionUtils.dfy

+9-24
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,19 @@ module {:options "/functionSyntax:4" } HierarchicalVersionUtils {
156156
input: Types.EncryptionContextString
157157
): (output: Result<Types.EncryptionContext, string>)
158158
ensures output.Success? ==> |output.value| == |input| // Output map size equals input map size
159-
ensures output.Failure? ==> output.error == "Unable to encode string"
160159
{
161-
var encodedEncryptionContext
162-
:= set k <- input
163-
::
164-
(UTF8.Encode(k), UTF8.Encode(input[k]), k);
160+
var encodedInputResult: seq<(string, (UTF8.ValidUTF8Bytes, UTF8.ValidUTF8Bytes))> :- Seq.MapWithResult(
161+
// Dafny requires the type of the element being mapped over, or it feaks out.
162+
(strKey: string)
163+
=>
164+
var keyValueUtf8 :- Utf8EncodeKeyValue(strKey, input[strKey]);
165+
Success(strKey, keyValueUtf8),
166+
input.Keys
167+
);
165168

166-
if (forall i <- encodedEncryptionContext
167-
::
168-
&& i.0.Success?
169-
&& i.1.Success?)
170-
then
171-
var resultMap := map i <- encodedEncryptionContext :: i.0.value := i.1.value;
172-
if |resultMap| == |input| then
173-
Success(resultMap)
174-
else
175-
Failure("Unable to encode string")
176-
else
177-
Failure("Unable to encode string")
178169
}
179170

180-
function method Utf8EncodeKeyValue(
171+
function Utf8EncodeKeyValue(
181172
strKey: string,
182173
strValue: string
183174
) : (res: Result<(UTF8.ValidUTF8Bytes, UTF8.ValidUTF8Bytes), Types.Error>)
@@ -199,12 +190,6 @@ module {:options "/functionSyntax:4" } HierarchicalVersionUtils {
199190
Success((key, value))
200191
}
201192

202-
function method WrapStringToError(e: string)
203-
:(ret: Types.Error)
204-
{
205-
Types.KeyStoreException( message := e )
206-
}
207-
208193
// Helper function to decode encryption context from UTF8 bytes map to string map
209194
function DecodeEncryptionContext(
210195
input: Types.EncryptionContext

0 commit comments

Comments
 (0)