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:
parent
2a2af3f72f
commit
c515bc66f1
3 changed files with 19 additions and 2 deletions
|
|
@ -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)},
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue