Skip to content

Commit

Permalink
password-hash: fix needless_as_bytes Clippy lint (#1715)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov authored Nov 18, 2024
1 parent f5266b8 commit 8bb3381
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions password-hash/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl FromStr for ParamsString {
type Err = Error;

fn from_str(s: &str) -> Result<Self> {
if s.as_bytes().len() > MAX_LENGTH {
if s.len() > MAX_LENGTH {
return Err(Error::ParamsMaxExceeded);
}

Expand Down Expand Up @@ -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,
}))
}
}
Expand Down
4 changes: 2 additions & 2 deletions password-hash/src/salt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
let length = input.as_bytes().len();
let length = input.len();

if length < Self::MIN_LENGTH {
return Err(Error::SaltInvalid(InvalidValue::TooShort));
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion password-hash/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
if input.as_bytes().len() > Self::MAX_LENGTH {
if input.len() > Self::MAX_LENGTH {
return Err(Error::ParamValueInvalid(InvalidValue::TooLong));
}

Expand Down

0 comments on commit 8bb3381

Please sign in to comment.