diff options
author | Florian Klink <flokli@flokli.de> | 2023-10-14T16·48+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-10-14T17·55+0000 |
commit | 4ae0f428bd207fdf3730d0f6ff73c7410ae9cd7b (patch) | |
tree | 341376899389f822e4bd40b3843aba8954fc77a3 /tvix/nix-compat/src/nixhash/algos.rs | |
parent | 786b0324a9df1a63606bae72011978fc415f6f07 (diff) |
refactor(tvix/nix-compat): make NixHash an enum with fixed-len bytes r/6807
Less Vec<u8> passed around. Change-Id: Ie153a6bfaa084d7490ffa38634efdf5f3c31a768 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9722 Reviewed-by: Connor Brewster <cbrewster@hey.com> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/nixhash/algos.rs')
-rw-r--r-- | tvix/nix-compat/src/nixhash/algos.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tvix/nix-compat/src/nixhash/algos.rs b/tvix/nix-compat/src/nixhash/algos.rs index 45cc242dc330..f189eba09db6 100644 --- a/tvix/nix-compat/src/nixhash/algos.rs +++ b/tvix/nix-compat/src/nixhash/algos.rs @@ -13,6 +13,18 @@ pub enum HashAlgo { Sha512, } +impl HashAlgo { + // return the number of bytes in the digest of the given hash algo. + pub fn digest_length(&self) -> usize { + match self { + HashAlgo::Sha1 => 20, + HashAlgo::Sha256 => 32, + HashAlgo::Sha512 => 64, + HashAlgo::Md5 => 16, + } + } +} + impl Display for HashAlgo { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match &self { |