1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-02 07:00:59 +01:00

Provide a structured JSON serialisation of hashes

This commit is contained in:
Eelco Dolstra 2025-03-13 18:52:29 +01:00
parent 2a2af3f72f
commit c515bc66f1
3 changed files with 19 additions and 2 deletions

View file

@ -14,6 +14,8 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <nlohmann/json.hpp>
#include <sodium.h>
namespace nix {
@ -456,4 +458,13 @@ std::string_view printHashAlgo(HashAlgorithm ha)
}
}
void to_json(nlohmann::json & json, const Hash & hash)
{
json = nlohmann::json::object(
{
{"algo", printHashAlgo(hash.algo)},
{"base16", hash.to_string(HashFormat::Base16, false)},
});
}
}