From 4ae0f428bd207fdf3730d0f6ff73c7410ae9cd7b Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 14 Oct 2023 17:48:16 +0100 Subject: refactor(tvix/nix-compat): make NixHash an enum with fixed-len bytes Less Vec passed around. Change-Id: Ie153a6bfaa084d7490ffa38634efdf5f3c31a768 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9722 Reviewed-by: Connor Brewster Autosubmit: flokli Tested-by: BuildkiteCI --- tvix/nix-compat/src/derivation/mod.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'tvix/nix-compat/src/derivation/mod.rs') diff --git a/tvix/nix-compat/src/derivation/mod.rs b/tvix/nix-compat/src/derivation/mod.rs index 0e98e24f43..3c08d61831 100644 --- a/tvix/nix-compat/src/derivation/mod.rs +++ b/tvix/nix-compat/src/derivation/mod.rs @@ -168,7 +168,8 @@ impl Derivation { // This is not the [NixHash::to_nix_hash_string], but without the sha256: prefix). for (drv_path, output_names) in &self.input_derivations { replaced_input_derivations.insert( - data_encoding::HEXLOWER.encode(&fn_get_derivation_or_fod_hash(drv_path).digest), + data_encoding::HEXLOWER + .encode(fn_get_derivation_or_fod_hash(drv_path).digest_as_bytes()), output_names.clone(), ); } @@ -186,12 +187,7 @@ impl Derivation { hasher.finalize().to_vec() }); - // We populate the struct directly, as we know the sha256 digest has the - // right size. - NixHash { - algo: crate::nixhash::HashAlgo::Sha256, - digest: digest.to_vec(), - } + NixHash::Sha256(digest.try_into().unwrap()) } /// This calculates all output paths of a Derivation and updates the struct. -- cgit 1.4.1