From 5e7ee808de8bdc353f80401e8fd8a310a2622f4b Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 13 Sep 2025 08:32:26 -0400 Subject: [PATCH] `nlohmann::json` instance and JSON Schema for `Hash` Improving and codifying our experimental JSON interfacing. Co-Authored-By: Robert Hensing --- doc/manual/meson.build | 2 +- doc/manual/package.nix | 2 + doc/manual/source/protocols/json/hash.md | 26 ++++ .../source/protocols/json/schema/hash-v1 | 1 + .../source/protocols/json/schema/hash-v1.yaml | 30 ++++- src/json-schema-checks/hash | 1 + src/json-schema-checks/meson.build | 10 ++ src/json-schema-checks/package.nix | 1 + .../data/hash/blake3-base64.json | 5 + .../data/hash/sha256-base16.json | 5 + .../data/hash/sha256-base64.json | 5 + src/libutil-tests/data/hash/sha256-nix32.json | 5 + src/libutil-tests/data/hash/simple.json | 5 + src/libutil-tests/hash.cc | 111 ++++++++++++++++-- src/libutil/hash.cc | 48 ++++++-- src/libutil/include/nix/util/hash.hh | 19 ++- 16 files changed, 252 insertions(+), 24 deletions(-) create mode 120000 doc/manual/source/protocols/json/schema/hash-v1 create mode 120000 src/json-schema-checks/hash create mode 100644 src/libutil-tests/data/hash/blake3-base64.json create mode 100644 src/libutil-tests/data/hash/sha256-base16.json create mode 100644 src/libutil-tests/data/hash/sha256-base64.json create mode 100644 src/libutil-tests/data/hash/sha256-nix32.json create mode 100644 src/libutil-tests/data/hash/simple.json diff --git a/doc/manual/meson.build b/doc/manual/meson.build index 7090c949c..fdea40098 100644 --- a/doc/manual/meson.build +++ b/doc/manual/meson.build @@ -88,7 +88,7 @@ manual = custom_target( @0@ @INPUT0@ @CURRENT_SOURCE_DIR@ > @DEPFILE@ @0@ @INPUT1@ summary @2@ < @CURRENT_SOURCE_DIR@/source/SUMMARY.md.in > @2@/source/SUMMARY.md sed -e 's|@version@|@3@|g' < @INPUT2@ > @2@/book.toml - @4@ -r --include='*.md' @CURRENT_SOURCE_DIR@/ @2@/ + @4@ -r -L --include='*.md' @CURRENT_SOURCE_DIR@/ @2@/ (cd @2@; RUST_LOG=warn @1@ build -d @2@ 3>&2 2>&1 1>&3) | { grep -Fv "because fragment resolution isn't implemented" || :; } 3>&2 2>&1 1>&3 rm -rf @2@/manual mv @2@/html @2@/manual diff --git a/doc/manual/package.nix b/doc/manual/package.nix index 7b94721ae..30486869e 100644 --- a/doc/manual/package.nix +++ b/doc/manual/package.nix @@ -33,6 +33,8 @@ mkMesonDerivation (finalAttrs: { fileset.difference (fileset.unions [ ../../.version + # For example JSON + ../../src/libutil-tests/data/hash # Too many different types of files to filter for now ../../doc/manual ./. diff --git a/doc/manual/source/protocols/json/hash.md b/doc/manual/source/protocols/json/hash.md index d2bdf1062..efd920086 100644 --- a/doc/manual/source/protocols/json/hash.md +++ b/doc/manual/source/protocols/json/hash.md @@ -1,5 +1,31 @@ {{#include hash-v1-fixed.md}} +## Examples + +### SHA-256 with Base64 encoding + +```json +{{#include schema/hash-v1/sha256-base64.json}} +``` + +### SHA-256 with Base16 (hexadecimal) encoding + +```json +{{#include schema/hash-v1/sha256-base16.json}} +``` + +### SHA-256 with Nix32 encoding + +```json +{{#include schema/hash-v1/sha256-nix32.json}} +``` + +### BLAKE3 with Base64 encoding + +```json +{{#include schema/hash-v1/blake3-base64.json}} +``` +