Remove unnecessary UTF-8 conversion in hash parsing (#11110)

## Summary

I believe this is a no-op?
This commit is contained in:
Charlie Marsh 2025-01-30 13:55:46 -05:00 committed by GitHub
parent d514743b1a
commit ee31e1f11b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 15 deletions

View file

@ -109,10 +109,7 @@ impl SimpleHtml {
debug!("{err}"); debug!("{err}");
Hashes::default() Hashes::default()
} }
Err( Err(err @ HashError::UnsupportedHashAlgorithm(..)) => {
err
@ (HashError::UnsupportedHashAlgorithm(..) | HashError::NonUtf8(..)),
) => {
// If the URL references a hash, but it's unsupported, error. // If the URL references a hash, but it's unsupported, error.
return Err(err.into()); return Err(err.into());
} }

View file

@ -192,8 +192,7 @@ impl Hashes {
match name { match name {
"md5" => { "md5" => {
let md5 = std::str::from_utf8(value.as_bytes())?; let md5 = value.to_owned().into_boxed_str();
let md5 = md5.to_owned().into_boxed_str();
Ok(Hashes { Ok(Hashes {
md5: Some(md5), md5: Some(md5),
sha256: None, sha256: None,
@ -202,8 +201,7 @@ impl Hashes {
}) })
} }
"sha256" => { "sha256" => {
let sha256 = std::str::from_utf8(value.as_bytes())?; let sha256 = value.to_owned().into_boxed_str();
let sha256 = sha256.to_owned().into_boxed_str();
Ok(Hashes { Ok(Hashes {
md5: None, md5: None,
sha256: Some(sha256), sha256: Some(sha256),
@ -212,8 +210,7 @@ impl Hashes {
}) })
} }
"sha384" => { "sha384" => {
let sha384 = std::str::from_utf8(value.as_bytes())?; let sha384 = value.to_owned().into_boxed_str();
let sha384 = sha384.to_owned().into_boxed_str();
Ok(Hashes { Ok(Hashes {
md5: None, md5: None,
sha256: None, sha256: None,
@ -222,8 +219,7 @@ impl Hashes {
}) })
} }
"sha512" => { "sha512" => {
let sha512 = std::str::from_utf8(value.as_bytes())?; let sha512 = value.to_owned().into_boxed_str();
let sha512 = sha512.to_owned().into_boxed_str();
Ok(Hashes { Ok(Hashes {
md5: None, md5: None,
sha256: None, sha256: None,
@ -419,9 +415,6 @@ pub enum HashError {
"Unsupported hash algorithm (expected one of: `md5`, `sha256`, `sha384`, or `sha512`) on: `{0}`" "Unsupported hash algorithm (expected one of: `md5`, `sha256`, `sha384`, or `sha512`) on: `{0}`"
)] )]
UnsupportedHashAlgorithm(String), UnsupportedHashAlgorithm(String),
#[error("Non-UTF-8 hash digest")]
NonUtf8(#[from] std::str::Utf8Error),
} }
#[cfg(test)] #[cfg(test)]