From 98e6936301dadc3400cb361a787cac8215c7bab8 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 14 Mar 2024 14:01:41 +0200 Subject: [PATCH] refactor(nix-compat/store_path/utils): move helper function in This is only used inside this function, in 2 of the match cases. Change-Id: Ib361f5ee0e3b203802f7d05b9a7f332d14bbcf80 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11143 Autosubmit: flokli Reviewed-by: John Ericson Tested-by: BuildkiteCI --- tvix/nix-compat/src/store_path/utils.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tvix/nix-compat/src/store_path/utils.rs b/tvix/nix-compat/src/store_path/utils.rs index d054d5955..d060e0eac 100644 --- a/tvix/nix-compat/src/store_path/utils.rs +++ b/tvix/nix-compat/src/store_path/utils.rs @@ -66,6 +66,13 @@ pub fn build_ca_path<'a, S: AsRef, I: IntoIterator>( return Err(BuildStorePathError::InvalidReference()); } + /// Helper function, used for the non-sha256 [CAHash::Nar] and all [CAHash::Flat]. + fn fixed_out_digest(prefix: &str, hash: &NixHash) -> [u8; 32] { + Sha256::new_with_prefix(format!("{}:{}:", prefix, hash.to_nix_hex_string())) + .finalize() + .into() + } + let (ty, inner_digest) = match &ca_hash { CAHash::Text(ref digest) => (make_references_string("text", references, false), *digest), CAHash::Nar(NixHash::Sha256(ref digest)) => ( @@ -101,14 +108,6 @@ pub fn build_ca_path<'a, S: AsRef, I: IntoIterator>( .map_err(BuildStorePathError::InvalidStorePath) } -/// Helper function, used in [build_ca_path] for the non-sha256 [CAHash::Nar] -/// and [CAHash::Flat]. -fn fixed_out_digest(prefix: &str, hash: &NixHash) -> [u8; 32] { - Sha256::new_with_prefix(format!("{}:{}:", prefix, hash.to_nix_hex_string())) - .finalize() - .into() -} - /// For given NAR sha256 digest and name, return the new [StorePathRef] this /// would have, or an error, in case the name is invalid. pub fn build_nar_based_store_path<'a>(