From ee31e1f11ba49cfb7fe2020863b1e5571ffaf6bb Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 30 Jan 2025 13:55:46 -0500 Subject: [PATCH] Remove unnecessary UTF-8 conversion in hash parsing (#11110) ## Summary I believe this is a no-op? --- crates/uv-client/src/html.rs | 5 +---- crates/uv-pypi-types/src/simple_json.rs | 15 ++++----------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/crates/uv-client/src/html.rs b/crates/uv-client/src/html.rs index cda16dfca..5972a0ae8 100644 --- a/crates/uv-client/src/html.rs +++ b/crates/uv-client/src/html.rs @@ -109,10 +109,7 @@ impl SimpleHtml { debug!("{err}"); Hashes::default() } - Err( - err - @ (HashError::UnsupportedHashAlgorithm(..) | HashError::NonUtf8(..)), - ) => { + Err(err @ HashError::UnsupportedHashAlgorithm(..)) => { // If the URL references a hash, but it's unsupported, error. return Err(err.into()); } diff --git a/crates/uv-pypi-types/src/simple_json.rs b/crates/uv-pypi-types/src/simple_json.rs index 5d6868e8d..88b430fdf 100644 --- a/crates/uv-pypi-types/src/simple_json.rs +++ b/crates/uv-pypi-types/src/simple_json.rs @@ -192,8 +192,7 @@ impl Hashes { match name { "md5" => { - let md5 = std::str::from_utf8(value.as_bytes())?; - let md5 = md5.to_owned().into_boxed_str(); + let md5 = value.to_owned().into_boxed_str(); Ok(Hashes { md5: Some(md5), sha256: None, @@ -202,8 +201,7 @@ impl Hashes { }) } "sha256" => { - let sha256 = std::str::from_utf8(value.as_bytes())?; - let sha256 = sha256.to_owned().into_boxed_str(); + let sha256 = value.to_owned().into_boxed_str(); Ok(Hashes { md5: None, sha256: Some(sha256), @@ -212,8 +210,7 @@ impl Hashes { }) } "sha384" => { - let sha384 = std::str::from_utf8(value.as_bytes())?; - let sha384 = sha384.to_owned().into_boxed_str(); + let sha384 = value.to_owned().into_boxed_str(); Ok(Hashes { md5: None, sha256: None, @@ -222,8 +219,7 @@ impl Hashes { }) } "sha512" => { - let sha512 = std::str::from_utf8(value.as_bytes())?; - let sha512 = sha512.to_owned().into_boxed_str(); + let sha512 = value.to_owned().into_boxed_str(); Ok(Hashes { md5: None, sha256: None, @@ -419,9 +415,6 @@ pub enum HashError { "Unsupported hash algorithm (expected one of: `md5`, `sha256`, `sha384`, or `sha512`) on: `{0}`" )] UnsupportedHashAlgorithm(String), - - #[error("Non-UTF-8 hash digest")] - NonUtf8(#[from] std::str::Utf8Error), } #[cfg(test)]