diff options
author | Florian Klink <flokli@flokli.de> | 2023-10-14T20·23+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-10-15T02·21+0000 |
commit | cb1a14334a7722e868058a6dda2176ae2f1bd52b (patch) | |
tree | d83bf0f958045a65d63099db7d3e1ec7e459ba8e /tvix/nix-compat | |
parent | e3d72cc4cb6714f683e97e8405f296977335efa6 (diff) |
refactor(nix-compat/nixhash): box sha512 r/6811
Limit the amount of memory consumed on the stack for NixHash. Sha512 isn't used that often, so it's fine if we heap-allocate it. Change-Id: I4a9eecd20c6184610124dc130c41bfa5d0dc04c5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9726 Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de> Reviewed-by: Connor Brewster <cbrewster@hey.com>
Diffstat (limited to 'tvix/nix-compat')
-rw-r--r-- | tvix/nix-compat/src/nixhash/mod.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/tvix/nix-compat/src/nixhash/mod.rs b/tvix/nix-compat/src/nixhash/mod.rs index 727f1280eaa0..8cc918b04322 100644 --- a/tvix/nix-compat/src/nixhash/mod.rs +++ b/tvix/nix-compat/src/nixhash/mod.rs @@ -14,7 +14,7 @@ pub enum NixHash { Md5([u8; 16]), Sha1([u8; 20]), Sha256([u8; 32]), - Sha512([u8; 64]), + Sha512(Box<[u8; 64]>), } impl NixHash { @@ -34,7 +34,7 @@ impl NixHash { NixHash::Md5(digest) => digest, NixHash::Sha1(digest) => digest, NixHash::Sha256(digest) => digest, - NixHash::Sha512(digest) => digest, + NixHash::Sha512(digest) => digest.as_ref(), } } @@ -73,7 +73,7 @@ pub fn from_algo_and_digest(algo: HashAlgo, digest: &[u8]) -> Result<NixHash, Er HashAlgo::Md5 => NixHash::Md5(digest.try_into().unwrap()), HashAlgo::Sha1 => NixHash::Sha1(digest.try_into().unwrap()), HashAlgo::Sha256 => NixHash::Sha256(digest.try_into().unwrap()), - HashAlgo::Sha512 => NixHash::Sha512(digest.try_into().unwrap()), + HashAlgo::Sha512 => NixHash::Sha512(Box::new(digest.try_into().unwrap())), }) } @@ -307,7 +307,7 @@ mod tests { /// Test parsing a hash string in various formats, and also when/how the out-of-band algo is needed. #[test_case(&NixHash::Sha1(DIGEST_SHA1); "sha1")] #[test_case(&NixHash::Sha256(DIGEST_SHA256); "sha256")] - #[test_case(&NixHash::Sha512(DIGEST_SHA512); "sha512")] + #[test_case(&NixHash::Sha512(Box::new(DIGEST_SHA512)); "sha512")] #[test_case(&NixHash::Md5(DIGEST_MD5); "md5")] fn from_str(expected_hash: &NixHash) { let algo = &expected_hash.algo(); |