Skip to content

Commit d9f2d27

Browse files
committed
m
1 parent 15ecd4f commit d9f2d27

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

DynamoDbEncryption/dafny/DynamoDbEncryption/src/DynamoToStruct.dfy

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ module DynamoToStruct {
154154
Success(SeqPosToUInt32(x, pos))
155155
}
156156

157-
// This is safe because are dealing with DynamoDB items, and so no numbers wil exceed 400K
157+
// This is safe because are dealing with DynamoDB items, and so no numbers will exceed 400K
158158
function method {:opaque} Add32(x : uint32, y : uint32) : (ret : uint32)
159159
ensures x as uint64 + y as uint64 <= UINT32_MAX as uint64
160160
ensures ret == x + y
@@ -999,7 +999,7 @@ module DynamoToStruct {
999999
else
10001000
assert serialized_size == |serialized| as uint32;
10011001
var nval :- BytesToAttr(serialized, TerminalTypeId, Some(len), depth+1, new_pos);
1002-
var new_pos := new_pos + nval.len;
1002+
var new_pos := Add32(new_pos, nval.len);
10031003
var nattr := AttributeValue.L(resultList.val.L + [nval.val]);
10041004
var nResultList := AttrValueAndLength(nattr, Add32(resultList.len, new_pos-pos));
10051005
Success((nResultList, new_pos))
@@ -1121,7 +1121,7 @@ module DynamoToStruct {
11211121

11221122
// get value and construct result
11231123
var nval :- BytesToAttr(serialized, TerminalTypeId_value, None, depth+1, pos);
1124-
var pos := pos + nval.len;
1124+
var pos := Add32(pos, nval.len);
11251125

11261126
//= specification/dynamodb-encryption-client/ddb-attribute-serialization.md#key-value-pair-entries
11271127
//# This sequence MUST NOT contain duplicate [Map Keys](#map-key).
@@ -1278,23 +1278,32 @@ module DynamoToStruct {
12781278
else
12791279
var len : uint32 :- BigEndianPosToU32(value, pos);
12801280
var pos : uint32 := pos + LENGTH_LEN32;
1281-
DeserializeStringSet(value[pos..], len, Add32_3(value_size - pos, LENGTH_LEN32, lengthBytes), AttrValueAndLength(AttributeValue.SS([]), LENGTH_LEN32+lengthBytes))
1281+
var retval :- DeserializeStringSet(value[pos..], len, Add32_3(value_size - pos, LENGTH_LEN32, lengthBytes), AttrValueAndLength(AttributeValue.SS([]), LENGTH_LEN32+lengthBytes));
1282+
// this is not needed with Dafny 4.10
1283+
assume {:axiom} Add32(pos, retval.len) <= |value| as uint32;
1284+
Success(retval)
12821285

12831286
else if typeId == SE.NUMBER_SET then
12841287
if value_size - pos < LENGTH_LEN32 then
12851288
Failure("Number Set Structured Data has less than 4 bytes")
12861289
else
12871290
var len : uint32 :- BigEndianPosToU32(value, pos);
12881291
var pos : uint32 := pos + LENGTH_LEN32;
1289-
DeserializeNumberSet(value[pos..], len, Add32_3(value_size - pos, LENGTH_LEN32, lengthBytes), AttrValueAndLength(AttributeValue.NS([]), LENGTH_LEN32 + lengthBytes))
1292+
var retval :- DeserializeNumberSet(value[pos..], len, Add32_3(value_size - pos, LENGTH_LEN32, lengthBytes), AttrValueAndLength(AttributeValue.NS([]), LENGTH_LEN32 + lengthBytes));
1293+
// this is not needed with Dafny 4.10
1294+
assume {:axiom} Add32(pos, retval.len) <= |value| as uint32;
1295+
Success(retval)
12901296

12911297
else if typeId == SE.BINARY_SET then
12921298
if value_size - pos < LENGTH_LEN32 then
12931299
Failure("Binary Set Structured Data has less than LENGTH_LEN bytes")
12941300
else
12951301
var len : uint32 :- BigEndianPosToU32(value, pos);
12961302
var pos : uint32 := pos + LENGTH_LEN32;
1297-
DeserializeBinarySet(value[pos..], len, Add32_3(value_size - pos, LENGTH_LEN32, lengthBytes), AttrValueAndLength(AttributeValue.BS([]), LENGTH_LEN32 + lengthBytes))
1303+
var retval :- DeserializeBinarySet(value[pos..], len, Add32_3(value_size - pos, LENGTH_LEN32, lengthBytes), AttrValueAndLength(AttributeValue.BS([]), LENGTH_LEN32 + lengthBytes));
1304+
// this is not needed with Dafny 4.10
1305+
assume {:axiom} Add32(pos, retval.len) <= |value| as uint32;
1306+
Success(retval)
12981307

12991308
else if typeId == SE.MAP then
13001309
if value_size < Add32(LENGTH_LEN32, pos) then
@@ -1303,7 +1312,10 @@ module DynamoToStruct {
13031312
var len : uint32 :- BigEndianPosToU32(value, pos);
13041313
var pos : uint32 := pos + LENGTH_LEN32;
13051314
var resultMap := AttrValueAndLength(AttributeValue.M(map[]), LENGTH_LEN32 + lengthBytes);
1306-
DeserializeMap(value, pos, pos - resultMap.len, len, depth, resultMap)
1315+
var retval :- DeserializeMap(value, pos, pos - resultMap.len, len, depth, resultMap);
1316+
// this is not needed with Dafny 4.10
1317+
assume {:axiom} Add32(pos, retval.len) <= |value| as uint32;
1318+
Success(retval)
13071319

13081320
else if typeId == SE.LIST then
13091321
if value_size < Add32(LENGTH_LEN32, pos) then
@@ -1315,7 +1327,10 @@ module DynamoToStruct {
13151327
assert value_size == |value| as uint32;
13161328
assert pos <= |value| as uint32;
13171329
var resultList := AttrValueAndLength(AttributeValue.L([]), LENGTH_LEN32 + lengthBytes);
1318-
DeserializeList(value, pos, pos - resultList.len, len, depth, resultList)
1330+
var retval :- DeserializeList(value, pos, pos - resultList.len, len, depth, resultList);
1331+
// this is not needed with Dafny 4.10
1332+
assume {:axiom} Add32(pos, retval.len) <= |value| as uint32;
1333+
Success(retval)
13191334
else
13201335
Failure("Unsupported TerminalTypeId")
13211336

TestVectors/dafny/DDBEncryption/src/DecryptManifest.dfy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ module {:options "-functionSyntax:4"} DecryptManifest {
113113

114114
function LogFileName() : Option<string>
115115
{
116-
// if OsLang.GetOsShort() == "Windows" && OsLang.GetLanguageShort() == "Dotnet" then
117-
// "..\\..\\PerfLog.txt"
118-
// else
119116
Some("../../PerfLog.txt")
120117
}
121118

0 commit comments

Comments
 (0)