From 963546bd37c3aeabff362007fe68c65b96f7623e Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 3 Jun 2025 22:21:44 +0300 Subject: [PATCH] refactor(nix-compat/nixhash): s/InvalidEncodedDigestLength/InvalidDigestLength/ This error is used for invalid digest lengths for a passed HashAlgo, not just when they're encoded (as can be seen in from_algo_and_digest). Change-Id: I7604846ae133df1be516a1f7ab28efd2a5775145 Reviewed-on: https://cl.snix.dev/c/snix/+/30551 Reviewed-by: Ilan Joselevich Tested-by: besadii Autosubmit: Florian Klink --- snix/nix-compat/src/nixhash/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/snix/nix-compat/src/nixhash/mod.rs b/snix/nix-compat/src/nixhash/mod.rs index 48407c0bc..507242690 100644 --- a/snix/nix-compat/src/nixhash/mod.rs +++ b/snix/nix-compat/src/nixhash/mod.rs @@ -157,7 +157,7 @@ impl Serialize for NixHash { /// the passed algo. pub fn from_algo_and_digest(algo: HashAlgo, digest: &[u8]) -> NixHashResult { if digest.len() != algo.digest_length() { - return Err(Error::InvalidEncodedDigestLength(digest.len(), algo)); + return Err(Error::InvalidDigestLength(digest.len(), algo)); } Ok(match algo { @@ -176,7 +176,7 @@ pub enum Error { #[error("invalid SRI string: {0}")] InvalidSRI(String), #[error("invalid encoded digest length '{0}' for algo {1}")] - InvalidEncodedDigestLength(usize, HashAlgo), + InvalidDigestLength(usize, HashAlgo), #[error("invalid base16 encoding: {0}")] InvalidBase16Encoding(data_encoding::DecodeError), #[error("invalid base32 encoding: {0}")] @@ -301,7 +301,7 @@ pub fn from_sri_str(s: &str) -> NixHashResult { // if the digest string is too small to fit even the BASE64_NOPAD version, bail out. if digest_str.len() < BASE64_NOPAD.encode_len(algo.digest_length()) { - return Err(Error::InvalidEncodedDigestLength(digest_str.len(), algo)); + return Err(Error::InvalidDigestLength(digest_str.len(), algo)); } // trim potential padding, and use a version that does not do trailing bit @@ -336,7 +336,7 @@ fn decode_digest(s: &[u8], algo: HashAlgo) -> NixHashResult { .decode(s.as_ref()) .map_err(Error::InvalidBase64Encoding)? } else { - Err(Error::InvalidEncodedDigestLength(s.len(), algo))? + Err(Error::InvalidDigestLength(s.len(), algo))? }; Ok(from_algo_and_digest(algo, &digest).unwrap())