From 8bb338103292e9e709c9b45009c568ed9a6276f9 Mon Sep 17 00:00:00 2001 From: Artyom Pavlov Date: Mon, 18 Nov 2024 16:51:28 +0300 Subject: [PATCH] password-hash: fix `needless_as_bytes` Clippy lint (#1715) --- password-hash/src/params.rs | 6 +++--- password-hash/src/salt.rs | 4 ++-- password-hash/src/value.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/password-hash/src/params.rs b/password-hash/src/params.rs index d23d279fe..0d8074099 100644 --- a/password-hash/src/params.rs +++ b/password-hash/src/params.rs @@ -173,7 +173,7 @@ impl FromStr for ParamsString { type Err = Error; fn from_str(s: &str) -> Result { - if s.as_bytes().len() > MAX_LENGTH { + if s.len() > MAX_LENGTH { return Err(Error::ParamsMaxExceeded); } @@ -201,11 +201,11 @@ impl FromStr for ParamsString { } let mut bytes = [0u8; MAX_LENGTH]; - bytes[..s.as_bytes().len()].copy_from_slice(s.as_bytes()); + bytes[..s.len()].copy_from_slice(s.as_bytes()); Ok(Self(Buffer { bytes, - length: s.as_bytes().len() as u8, + length: s.len() as u8, })) } } diff --git a/password-hash/src/salt.rs b/password-hash/src/salt.rs index 8ab8baf99..eba6876f6 100644 --- a/password-hash/src/salt.rs +++ b/password-hash/src/salt.rs @@ -103,7 +103,7 @@ impl<'a> Salt<'a> { /// Create a [`Salt`] from the given B64-encoded input string, validating /// [`Salt::MIN_LENGTH`] and [`Salt::MAX_LENGTH`] restrictions. pub fn from_b64(input: &'a str) -> Result { - let length = input.as_bytes().len(); + let length = input.len(); if length < Self::MIN_LENGTH { return Err(Error::SaltInvalid(InvalidValue::TooShort)); @@ -215,7 +215,7 @@ impl SaltString { // Assert `s` parses successfully as a `Salt` Salt::from_b64(s)?; - let len = s.as_bytes().len(); + let len = s.len(); let mut bytes = [0u8; Salt::MAX_LENGTH]; bytes[..len].copy_from_slice(s.as_bytes()); diff --git a/password-hash/src/value.rs b/password-hash/src/value.rs index aacc85d53..f60a75590 100644 --- a/password-hash/src/value.rs +++ b/password-hash/src/value.rs @@ -50,7 +50,7 @@ impl<'a> Value<'a> { /// Parse a [`Value`] from the provided `str`, validating it according to /// the PHC string format's rules. pub fn new(input: &'a str) -> Result { - if input.as_bytes().len() > Self::MAX_LENGTH { + if input.len() > Self::MAX_LENGTH { return Err(Error::ParamValueInvalid(InvalidValue::TooLong)); }