From 8694694b7452595fee4ed510ce322100aac003b7 Mon Sep 17 00:00:00 2001 From: edef Date: Fri, 10 Nov 2023 16:10:02 +0000 Subject: feat(nix-compat/narinfo): permit non-SHA256 CAHash::Nar This appears in the cache.nixos.org dataset. Change-Id: I055b60b9950a1a6a36c1b0576b957e11e1d4264b Reviewed-on: https://cl.tvl.fyi/c/depot/+/9990 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/nix-compat/src/narinfo.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'tvix/nix-compat') diff --git a/tvix/nix-compat/src/narinfo.rs b/tvix/nix-compat/src/narinfo.rs index 1cd89d7c5840..6a070b35ac0f 100644 --- a/tvix/nix-compat/src/narinfo.rs +++ b/tvix/nix-compat/src/narinfo.rs @@ -351,9 +351,8 @@ pub fn parse_ca(s: &str) -> Option { Some(CAHash::Text(digest)) } "fixed" => { - if let Some(digest) = s.strip_prefix("r:sha256:") { - let digest = nixbase32::decode_fixed(digest).ok()?; - Some(CAHash::Nar(NixHash::Sha256(digest))) + if let Some(s) = s.strip_prefix("r:") { + parse_hash(s).map(CAHash::Nar) } else { parse_hash(s).map(CAHash::Flat) } @@ -459,10 +458,13 @@ pub enum Error { #[cfg(test)] mod test { + use hex_literal::hex; use lazy_static::lazy_static; use pretty_assertions::assert_eq; use std::{io, str}; + use crate::nixhash::{CAHash, NixHash}; + use super::NarInfo; lazy_static! { @@ -486,4 +488,27 @@ mod test { assert_eq!(input, output, "should roundtrip"); } } + + #[test] + fn ca_nar_hash_sha1() { + let parsed = NarInfo::parse( + r#"StorePath: /nix/store/k20pahypzvr49fy82cw5sx72hdfg3qcr-texlive-hyphenex-37354 +URL: nar/0i5biw0g01514llhfswxy6xfav8lxxdq1xg6ik7hgsqbpw0f06yi.nar.xz +Compression: xz +FileHash: sha256:0i5biw0g01514llhfswxy6xfav8lxxdq1xg6ik7hgsqbpw0f06yi +FileSize: 7120 +NarHash: sha256:0h1bm4sj1cnfkxgyhvgi8df1qavnnv94sd0v09wcrm971602shfg +NarSize: 22552 +References: +Sig: cache.nixos.org-1:u01BybwQhyI5H1bW1EIWXssMDhDDIvXOG5uh8Qzgdyjz6U1qg6DHhMAvXZOUStIj6X5t4/ufFgR8i3fjf0bMAw== +CA: fixed:r:sha1:1ak1ymbmsfx7z8kh09jzkr3a4dvkrfjw +"#).expect("should parse"); + + assert_eq!( + parsed.ca, + Some(CAHash::Nar(NixHash::Sha1(hex!( + "5cba3c77236ae4f9650270a27fbad375551fa60a" + )))) + ); + } } -- cgit 1.4.1