about summary refs log tree commit diff
path: root/tvix/nix-compat/src
diff options
context:
space:
mode:
authoredef <edef@edef.eu>2023-11-10T16·10+0000
committeredef <edef@edef.eu>2023-11-10T19·05+0000
commit8694694b7452595fee4ed510ce322100aac003b7 (patch)
treeaeeb7c2ba14a15d4ec13e7afc2df99acf785b545 /tvix/nix-compat/src
parentbdda10a2f54974053b1d78b801469f076e90a6da (diff)
feat(nix-compat/narinfo): permit non-SHA256 CAHash::Nar r/6980
This appears in the cache.nixos.org dataset.

Change-Id: I055b60b9950a1a6a36c1b0576b957e11e1d4264b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9990
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src')
-rw-r--r--tvix/nix-compat/src/narinfo.rs31
1 files changed, 28 insertions, 3 deletions
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<CAHash> {
             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"
+            ))))
+        );
+    }
 }