mirror of
https://github.com/NixOS/nix.git
synced 2025-12-19 23:41:07 +01:00
Use SRI hash (strings) as the official JSON format for Hash after all
The fact that we were introducing a conversion from the output of `nix path-info` into the input of `builtins.fetchTree` was the deciding factor. We want scripting outputs into inputs like that to be easy. Since JSON strings and objects are trivially distinguishable, we still have the option of introducing the JSON format as an alternative input scheme in the future, should we want to. (The output format would still be SRI in that case, presumably.)
This commit is contained in:
parent
401e08f839
commit
61de9222b0
44 changed files with 78 additions and 348 deletions
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"algorithm": "blake3",
|
||||
"format": "base16",
|
||||
"hash": "9e70ee1449965fb62d049040a1ed06ec377430da6ec13173e7c4fffcd28be980"
|
||||
}
|
||||
1
src/libutil-tests/data/hash/blake3.json
Normal file
1
src/libutil-tests/data/hash/blake3.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
"blake3-nnDuFEmWX7YtBJBAoe0G7Dd0MNpuwTFz58T//NKL6YA="
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"algorithm": "sha256",
|
||||
"format": "base16",
|
||||
"hash": "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b"
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"algorithm": "sha256",
|
||||
"format": "base64",
|
||||
"hash": "8OTC92xYkW7CWPJGhRvqCR0U1CR6L8PhhpRGGxgW4Ts="
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"algorithm": "sha256",
|
||||
"format": "nix32",
|
||||
"hash": "0fz12qc1nillhvhw6bvs4ka18789x8dqaipjb316x4aqdkvw5r7h"
|
||||
}
|
||||
1
src/libutil-tests/data/hash/sha256.json
Normal file
1
src/libutil-tests/data/hash/sha256.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
"sha256-8OTC92xYkW7CWPJGhRvqCR0U1CR6L8PhhpRGGxgW4Ts="
|
||||
1
src/libutil-tests/data/hash/sha512.json
Normal file
1
src/libutil-tests/data/hash/sha512.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
"sha256-8OTC92xYkW7CWPJGhRvqCR0U1CR6L8PhhpRGGxgW4Ts="
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"algorithm": "sha256",
|
||||
"format": "base16",
|
||||
"hash": "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b"
|
||||
}
|
||||
|
|
@ -215,9 +215,6 @@ struct HashJsonTest : virtual HashTest,
|
|||
::testing::WithParamInterface<std::pair<std::string_view, Hash>>
|
||||
{};
|
||||
|
||||
struct HashJsonParseFailureTest : virtual HashTest, ::testing::WithParamInterface<std::string_view>
|
||||
{};
|
||||
|
||||
struct BLAKE3HashJsonTest : virtual HashTest,
|
||||
BLAKE3HashTest,
|
||||
JsonCharacterizationTest<Hash>,
|
||||
|
|
@ -236,14 +233,6 @@ TEST_P(HashJsonTest, to_json)
|
|||
writeJsonTest(name, value);
|
||||
}
|
||||
|
||||
TEST_P(HashJsonParseFailureTest, from_json)
|
||||
{
|
||||
auto & name = GetParam();
|
||||
auto path = goldenMaster(Path{name} + ".json");
|
||||
auto encoded = json::parse(readFile(path));
|
||||
ASSERT_THROW(nlohmann::adl_serializer<Hash>::from_json(encoded), Error);
|
||||
}
|
||||
|
||||
TEST_P(BLAKE3HashJsonTest, from_json)
|
||||
{
|
||||
auto & [name, expected] = GetParam();
|
||||
|
|
@ -256,32 +245,25 @@ TEST_P(BLAKE3HashJsonTest, to_json)
|
|||
writeJsonTest(name, expected);
|
||||
}
|
||||
|
||||
// Round-trip tests (from_json + to_json) for base16 format only
|
||||
// (to_json always outputs base16)
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
HashJSON,
|
||||
HashJsonTest,
|
||||
::testing::Values(
|
||||
std::pair{
|
||||
"simple",
|
||||
"sha256",
|
||||
hashString(HashAlgorithm::SHA256, "asdf"),
|
||||
},
|
||||
std::pair{
|
||||
"sha256-base16",
|
||||
"sha512",
|
||||
hashString(HashAlgorithm::SHA256, "asdf"),
|
||||
}));
|
||||
|
||||
// Failure tests for unsupported formats (base64, nix32, sri)
|
||||
// These verify that non-base16 formats are rejected
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
HashJSONParseFailure, HashJsonParseFailureTest, ::testing::Values("sha256-base64", "sha256-nix32"));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(BLAKE3HashJSON, BLAKE3HashJsonTest, ([] {
|
||||
ExperimentalFeatureSettings mockXpSettings;
|
||||
mockXpSettings.set("experimental-features", "blake3-hashes");
|
||||
return ::testing::Values(
|
||||
std::pair{
|
||||
"blake3-base16",
|
||||
"blake3",
|
||||
hashString(HashAlgorithm::BLAKE3, "asdf", mockXpSettings),
|
||||
});
|
||||
}()));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue