about summary refs log tree commit diff
path: root/tvix/nix-compat/src/narinfo/mod.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-11-19T15·53+0200
committerflokli <flokli@flokli.de>2023-11-19T22·34+0000
commita834966efd64c1b2306241c3ef20f4258f6b9c4e (patch)
treef19e8bb71ee7b3eac478266e3a0e69f67ea6cef7 /tvix/nix-compat/src/narinfo/mod.rs
parentbb18556bf37475b096d7d39ecd27becbe7cafa01 (diff)
feat(tvix/nix-compat/narinfo): add fingerprint r/7043
This adds support to compute the fingerprint string, which is what's
ed25519-signed in binary caches.

Change-Id: I8947239c609896acfd7261f110450014bedf465a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10080
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/narinfo/mod.rs')
-rw-r--r--tvix/nix-compat/src/narinfo/mod.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/tvix/nix-compat/src/narinfo/mod.rs b/tvix/nix-compat/src/narinfo/mod.rs
index ac904099453e..e64fb10d7ac8 100644
--- a/tvix/nix-compat/src/narinfo/mod.rs
+++ b/tvix/nix-compat/src/narinfo/mod.rs
@@ -30,8 +30,11 @@ use crate::{
     store_path::StorePathRef,
 };
 
+mod fingerprint;
 mod signature;
 
+pub use fingerprint::fingerprint;
+
 pub use signature::{Signature, SignatureError};
 
 #[derive(Debug)]
@@ -282,6 +285,17 @@ impl<'a> NarInfo<'a> {
             flags,
         })
     }
+
+    /// Computes the fingerprint string for certain fields in this [NarInfo].
+    /// This fingerprint is signed in [self.signatures].
+    pub fn fingerprint(&self) -> String {
+        fingerprint(
+            &self.store_path,
+            &self.nar_hash,
+            self.nar_size,
+            self.references.iter(),
+        )
+    }
 }
 
 impl Display for NarInfo<'_> {