refactor(nix-compat/nixhash): drop (encoded) digest length
We use this for both encoded and unencoded strings (and the error message was missing), so this usize is pointless. Change-Id: Id2a1000f1b232896605cdd34349ee114a67dc268 Reviewed-on: https://cl.snix.dev/c/snix/+/30563 Tested-by: besadii Autosubmit: Florian Klink <flokli@flokli.de> Reviewed-by: edef <edef@edef.eu>
This commit is contained in:
parent
16136380ec
commit
63036b3c5e
1 changed files with 5 additions and 5 deletions
|
|
@ -111,7 +111,7 @@ impl NixHash {
|
||||||
/// the passed algo.
|
/// the passed algo.
|
||||||
pub fn from_algo_and_digest(algo: HashAlgo, digest: &[u8]) -> Result<NixHash, Error> {
|
pub fn from_algo_and_digest(algo: HashAlgo, digest: &[u8]) -> Result<NixHash, Error> {
|
||||||
if digest.len() != algo.digest_length() {
|
if digest.len() != algo.digest_length() {
|
||||||
return Err(Error::InvalidDigestLength(digest.len(), algo));
|
return Err(Error::InvalidDigestLength(algo));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(match algo {
|
Ok(match algo {
|
||||||
|
|
@ -171,7 +171,7 @@ impl NixHash {
|
||||||
|
|
||||||
// if the digest string is too small to fit even the BASE64_NOPAD version, bail out.
|
// 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()) {
|
if digest_str.len() < BASE64_NOPAD.encode_len(algo.digest_length()) {
|
||||||
return Err(Error::InvalidDigestLength(digest_str.len(), algo));
|
return Err(Error::InvalidDigestLength(algo));
|
||||||
}
|
}
|
||||||
|
|
||||||
// trim potential padding, and use a version that does not do trailing bit
|
// trim potential padding, and use a version that does not do trailing bit
|
||||||
|
|
@ -271,8 +271,8 @@ pub enum Error {
|
||||||
InvalidAlgo,
|
InvalidAlgo,
|
||||||
#[error("invalid SRI string")]
|
#[error("invalid SRI string")]
|
||||||
InvalidSRI,
|
InvalidSRI,
|
||||||
#[error("invalid encoded digest length '{0}' for algo {1}")]
|
#[error("invalid digest length for algo {0}")]
|
||||||
InvalidDigestLength(usize, HashAlgo),
|
InvalidDigestLength(HashAlgo),
|
||||||
#[error("invalid base16 encoding: {0}")]
|
#[error("invalid base16 encoding: {0}")]
|
||||||
InvalidBase16Encoding(data_encoding::DecodeError),
|
InvalidBase16Encoding(data_encoding::DecodeError),
|
||||||
#[error("invalid base32 encoding: {0}")]
|
#[error("invalid base32 encoding: {0}")]
|
||||||
|
|
@ -302,7 +302,7 @@ fn decode_digest(s: &[u8], algo: HashAlgo) -> Result<NixHash, Error> {
|
||||||
.decode(s.as_ref())
|
.decode(s.as_ref())
|
||||||
.map_err(Error::InvalidBase64Encoding)?
|
.map_err(Error::InvalidBase64Encoding)?
|
||||||
} else {
|
} else {
|
||||||
Err(Error::InvalidDigestLength(s.len(), algo))?
|
Err(Error::InvalidDigestLength(algo))?
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(NixHash::from_algo_and_digest(algo, &digest).unwrap())
|
Ok(NixHash::from_algo_and_digest(algo, &digest).unwrap())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue