Skip to content

Commit

Permalink
Fix clippy (nightly) warnings: needless call to as_bytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
chifflier committed Nov 14, 2024
1 parent 3c20607 commit e234fac
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/asn1_types/strings/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Tagged for &'_ str {
#[cfg(feature = "std")]
impl ToDer for &'_ str {
fn to_der_len(&self) -> Result<usize> {
let sz = self.as_bytes().len();
let sz = self.len();
if sz < 127 {
// 1 (class+tag) + 1 (length) + len
Ok(2 + sz)
Expand All @@ -56,7 +56,7 @@ impl ToDer for &'_ str {
Class::Universal,
false,
Self::TAG,
Length::Definite(self.as_bytes().len()),
Length::Definite(self.len()),
);
header.write_der_header(writer).map_err(Into::into)
}
Expand Down
2 changes: 1 addition & 1 deletion src/asn1_types/strings/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Tagged for String {
#[cfg(feature = "std")]
impl ToDer for String {
fn to_der_len(&self) -> Result<usize> {
let sz = self.as_bytes().len();
let sz = self.len();
if sz < 127 {
// 1 (class+tag) + 1 (length) + len
Ok(2 + sz)
Expand Down
6 changes: 3 additions & 3 deletions src/asn1_types/strings/universalstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Tagged for UniversalString<'_> {
impl ToDer for UniversalString<'_> {
fn to_der_len(&self) -> Result<usize> {
// UCS-4: 4 bytes per character
let sz = self.data.as_bytes().len() * 4;
let sz = self.data.len() * 4;
if sz < 127 {
// 1 (class+tag) + 1 (length) + len
Ok(2 + sz)
Expand All @@ -125,7 +125,7 @@ impl ToDer for UniversalString<'_> {
Class::Universal,
false,
Self::TAG,
Length::Definite(self.data.as_bytes().len() * 4),
Length::Definite(self.data.len() * 4),
);
header.write_der_header(writer).map_err(Into::into)
}
Expand All @@ -134,6 +134,6 @@ impl ToDer for UniversalString<'_> {
self.data
.chars()
.try_for_each(|c| writer.write(&(c as u32).to_be_bytes()[..]).map(|_| ()))?;
Ok(self.data.as_bytes().len() * 4)
Ok(self.data.len() * 4)
}
}

0 comments on commit e234fac

Please sign in to comment.