Skip to content

chore(dafny): let FileIO deal in uint8 rather than bv8 #1746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions TestVectors/dafny/DDBEncryption/src/DecryptManifest.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ module {:options "-functionSyntax:4"} DecryptManifest {
{
var timeStamp :- expect Time.GetCurrentTimeStamp();
print timeStamp + " Decrypt : ", inFile, "\n";
var configBv :- expect FileIO.ReadBytesFromFile(inFile);
var configBytes := BvToBytes(configBv);
var configBytes :- expect FileIO.ReadBytesFromFile(inFile);
timeStamp :- expect Time.GetCurrentTimeStamp();
print timeStamp + " File Read.\n";
var json :- expect API.Deserialize(configBytes);
Expand Down
6 changes: 2 additions & 4 deletions TestVectors/dafny/DDBEncryption/src/EncryptManifest.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ module {:options "-functionSyntax:4"} EncryptManifest {
{
var timeStamp :- expect Time.GetCurrentTimeStamp();
print timeStamp + " Encrypt : ", inFile, "\n";
var configBv :- expect FileIO.ReadBytesFromFile(inFile);
var configBytes := BvToBytes(configBv);
var configBytes :- expect FileIO.ReadBytesFromFile(inFile);
timeStamp :- expect Time.GetCurrentTimeStamp();
print timeStamp + " File Read.\n";
var json :- expect API.Deserialize(configBytes);
Expand Down Expand Up @@ -212,8 +211,7 @@ module {:options "-functionSyntax:4"} EncryptManifest {

var final := Object(result + [("tests", Object(test))]);
var jsonBytes :- expect API.Serialize(final);
var jsonBv := BytesBv(jsonBytes);
var x :- expect FileIO.WriteBytesToFile(outFile, jsonBv);
var x :- expect FileIO.WriteBytesToFile(outFile, jsonBytes);

timeStamp :- expect Time.GetCurrentTimeStamp();
print timeStamp + " Tests Complete.\n";
Expand Down
7 changes: 3 additions & 4 deletions TestVectors/dafny/DDBEncryption/src/Index.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ module WrappedDDBEncryptionMain {
modifies keyVectors.Modifies
ensures keyVectors.ValidState()
{
var configBv := FileIO.ReadBytesFromFile(file);
if configBv.Failure? {
var configBytes := FileIO.ReadBytesFromFile(file);
if configBytes.Failure? {
print "Failed to open ", file, " continuing anyway.\n";
return Success(MakeEmptyTestVector());
}
var configBytes := BvToBytes(configBv.value);
var json :- expect API.Deserialize(configBytes);
var json :- expect API.Deserialize(configBytes.value);
output := ParseTestVector(json, prev, keyVectors);
if output.Failure? {
print output.error, "\n";
Expand Down
3 changes: 1 addition & 2 deletions TestVectors/dafny/DDBEncryption/src/TestVectors.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,7 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
jsonItems := jsonItems + [item];
}
var jsonBytes :- expect API.Serialize(Array(jsonItems));
var jsonBv := BytesBv(jsonBytes);
var x := FileIO.WriteBytesToFile(fileName, jsonBv);
var x := FileIO.WriteBytesToFile(fileName, jsonBytes);
expect x.Success?;
}

Expand Down
3 changes: 1 addition & 2 deletions TestVectors/dafny/DDBEncryption/src/WriteManifest.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ module {:options "-functionSyntax:4"} WriteManifest {
var final := Object(result + [("tests", Object(tests))]);

var jsonBytes :- expect API.Serialize(final);
var jsonBv := BytesBv(jsonBytes);
var x := FileIO.WriteBytesToFile(fileName, jsonBv);
var x := FileIO.WriteBytesToFile(fileName, jsonBytes);
expect x.Success?;
return Success(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ module {:options "-functionSyntax:4"} WriteSetPermutations {
return recs1 + recs2 + recs3 + recs4;
}

function BytesBv(bits: seq<BoundedInts.uint8>): seq<bv8>
{
seq(|bits|, i requires 0 <= i < |bits| => bits[i] as bv8)
}

method WriteSetPermutations()
{
var configs := GetConfigs();
Expand All @@ -132,11 +127,10 @@ module {:options "-functionSyntax:4"} WriteSetPermutations {
]))]);

var jsonBytes :- expect API.Serialize(whole);
var jsonBv := BytesBv(jsonBytes);

var _ :- expect FileIO.WriteBytesToFile(
"PermTest.json",
jsonBv
jsonBytes
);
}
}
2 changes: 1 addition & 1 deletion submodules/MaterialProviders
Loading