@@ -19,6 +19,7 @@ module {:options "/functionSyntax:4" } HierarchicalVersionUtils {
19
19
const BKC_DIGEST_LENGTH: uint8 := 48
20
20
type PlainTextTuple = s: seq < uint8> | |s| == 80 witness *
21
21
type BKCDigestError = e: Types. Error | (e. KeyStoreException? ) witness *
22
+ datatype Utf8KeyValue = Utf8KeyValue (key: UTF8 .ValidUTF8Bytes, value: UTF8 .ValidUTF8Bytes)
22
23
23
24
method ProvideCryptoClient (
24
25
Crypto?: Option <AtomicPrimitives .AtomicPrimitivesClient> := None
@@ -156,31 +157,23 @@ module {:options "/functionSyntax:4" } HierarchicalVersionUtils {
156
157
input: Types .EncryptionContextString
157
158
): (output: Result< Types. EncryptionContext, string > )
158
159
ensures output. Success? ==> |output. value| == |input| // Output map size equals input map size
159
- ensures output. Failure? ==> output. error == "Unable to encode string "
160
160
{
161
- var encodedEncryptionContext
162
- := set k < - input
163
- ::
164
- (UTF8. Encode (k), UTF8. Encode (input[k]), k);
165
-
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")
161
+ var encodedInputResult: seq < (Utf8KeyValue)> :- Seq. MapWithResult (
162
+ // Dafny requires the type of the element being mapped over, or it feaks out.
163
+ (strKey: string )
164
+ =>
165
+ var keyValueUtf8 :- Utf8EncodeKeyValue (strKey, input[strKey]);
166
+ Success (keyValueUtf8),
167
+ input. Keys
168
+ );
169
+ Success (map r | r in encodedInputResult :: r .key := r.value)
178
170
}
179
171
180
- function method Utf8EncodeKeyValue (
172
+
173
+ function Utf8EncodeKeyValue (
181
174
strKey: string ,
182
175
strValue: string
183
- ) : (res: Result< (UTF8 . ValidUTF8Bytes, UTF8 . ValidUTF8Bytes) , Types. Error> )
176
+ ) : (res: Result< Utf8KeyValue , Types. Error> )
184
177
ensures (UTF8.Encode(strKey). Success? && UTF8. Encode (strValue). Success?) <= => res. Success?
185
178
{
186
179
var key :- UTF8
@@ -196,13 +189,7 @@ module {:options "/functionSyntax:4" } HierarchicalVersionUtils {
196
189
=>
197
190
WrapStringToError ("Could not UTF8 Encode: " + strValue + " due to: " + eStr ));
198
191
199
- Success ((key, value))
200
- }
201
-
202
- function method WrapStringToError (e: string )
203
- :(ret: Types. Error)
204
- {
205
- Types. KeyStoreException ( message := e )
192
+ Success (Utf8KeyValue(key := key, value := value))
206
193
}
207
194
208
195
// Helper function to decode encryption context from UTF8 bytes map to string map
0 commit comments