refactor(tvix/nix-compat): cleanup parse_{ca,hash} and fmt structs

These were used to format to and parse from strings.

Move this to the CAHash and NixHash structs directly, and be explicit in
the name about which encoding for digests is used.

For output path calculation, nix encodes the nixpaths in hex, but for
writing out NARInfos, it's using nixbase32.

Change-Id: Ia585a76a3811b2609e7ce259fda66a29403b7e07
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10079
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
This commit is contained in:
Florian Klink 2023-11-19 19:50:56 +02:00 committed by clbot
parent a8d48d4d9c
commit ef8a8af0bf
6 changed files with 83 additions and 97 deletions

View file

@ -93,7 +93,7 @@ pub fn build_ca_path<B: AsRef<[u8]>, S: AsRef<str>, I: IntoIterator<Item = S>>(
NixHash::Sha256(
Sha256::new_with_prefix(format!(
"fixed:out:r:{}:",
hash.to_nix_hash_string()
hash.to_nix_hex_string()
))
.finalize()
.into(),
@ -115,12 +115,9 @@ pub fn build_ca_path<B: AsRef<[u8]>, S: AsRef<str>, I: IntoIterator<Item = S>>(
"output:out",
&{
NixHash::Sha256(
Sha256::new_with_prefix(format!(
"fixed:out:{}:",
hash.to_nix_hash_string()
))
.finalize()
.into(),
Sha256::new_with_prefix(format!("fixed:out:{}:", hash.to_nix_hex_string()))
.finalize()
.into(),
)
},
name,
@ -170,7 +167,7 @@ fn build_store_path_from_fingerprint_parts<B: AsRef<[u8]>>(
let digest = compress_hash(&{
let mut h = Sha256::new();
write!(h, "{ty}:{}:{STORE_DIR}:{name}", hash.to_nix_hash_string()).unwrap();
write!(h, "{ty}:{}:{STORE_DIR}:{name}", hash.to_nix_hex_string()).unwrap();
h.finalize()
});