Skip to content

Commit 94a4f05

Browse files
committed
chore: fix clippy warnings
1 parent c32f236 commit 94a4f05

4 files changed

Lines changed: 41 additions & 35 deletions

File tree

cesr/src/primitives/codes/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ impl FromStr for PrimitiveCode {
105105
fn from_str(s: &str) -> Result<Self, Self::Err> {
106106
use PrimitiveCode::*;
107107

108-
let parsers: &[fn(&str) -> Result<PrimitiveCode, Error>] = &[
108+
type ParserFn = fn(&str) -> Result<PrimitiveCode, Error>;
109+
110+
let parsers: &[ParserFn] = &[
109111
|s| Rand128Code::from_str(s).map(Random),
110112
|s| SeedCode::from_str(s).map(Seed),
111113
|s| AttachedSignatureCode::from_str(s).map(IndexedSignature),

cesr/src/variable_length.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::str::FromStr;
1+
use std::{fmt::Display, str::FromStr};
22

33
use nom::bytes::complete::take;
44

@@ -7,6 +7,7 @@ use crate::{
77
error::Error,
88
};
99

10+
#[allow(clippy::enum_variant_names)]
1011
pub enum VariableCodeSelector {
1112
ShortZeroLeadBytes,
1213
ShortOneLeadBytes,
@@ -53,16 +54,16 @@ impl VariableCodeSelector {
5354
}
5455
}
5556
}
56-
impl ToString for VariableCodeSelector {
57-
fn to_string(&self) -> String {
58-
match self {
59-
VariableCodeSelector::ShortZeroLeadBytes => "4".to_string(),
60-
VariableCodeSelector::ShortOneLeadBytes => "5".to_string(),
61-
VariableCodeSelector::ShortTwoLeadBytes => "6".to_string(),
62-
VariableCodeSelector::LongZeroLeadBytes => "7".to_string(),
63-
VariableCodeSelector::LongOneLeadBytes => "8".to_string(),
64-
VariableCodeSelector::LongTwoLeadBytes => "9".to_string(),
65-
}
57+
impl Display for VariableCodeSelector {
58+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59+
f.write_str(match self {
60+
VariableCodeSelector::ShortZeroLeadBytes => "4",
61+
VariableCodeSelector::ShortOneLeadBytes => "5",
62+
VariableCodeSelector::ShortTwoLeadBytes => "6",
63+
VariableCodeSelector::LongZeroLeadBytes => "7",
64+
VariableCodeSelector::LongOneLeadBytes => "8",
65+
VariableCodeSelector::LongTwoLeadBytes => "9",
66+
})
6667
}
6768
}
6869

@@ -97,13 +98,13 @@ pub enum SmallVariableLengthCode {
9798
Base64String,
9899
}
99100

100-
impl ToString for SmallVariableLengthCode {
101-
fn to_string(&self) -> String {
102-
match self {
103-
SmallVariableLengthCode::Base64String => "A".to_string(),
104-
SmallVariableLengthCode::HPKEBaseCipher => "F".to_string(),
105-
SmallVariableLengthCode::HPKEAuthCipher => "G".to_string(),
106-
}
101+
impl Display for SmallVariableLengthCode {
102+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
103+
f.write_str(match self {
104+
SmallVariableLengthCode::Base64String => "A",
105+
SmallVariableLengthCode::HPKEBaseCipher => "F",
106+
SmallVariableLengthCode::HPKEAuthCipher => "G",
107+
})
107108
}
108109
}
109110

@@ -126,12 +127,12 @@ pub enum LargeVariableLengthCode {
126127
HPKEAuthCipher,
127128
}
128129

129-
impl ToString for LargeVariableLengthCode {
130-
fn to_string(&self) -> String {
131-
match self {
132-
LargeVariableLengthCode::HPKEBaseCipher => "AAF".to_string(),
133-
LargeVariableLengthCode::HPKEAuthCipher => "AAG".to_string(),
134-
}
130+
impl Display for LargeVariableLengthCode {
131+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
132+
f.write_str(match self {
133+
LargeVariableLengthCode::HPKEBaseCipher => "AAF",
134+
LargeVariableLengthCode::HPKEAuthCipher => "AAG",
135+
})
135136
}
136137
}
137138

@@ -167,11 +168,11 @@ impl VariableLengthPrimitive {
167168
0 => (LeadBytes::Zero, from_text_to_bytes(encoded_value).unwrap()),
168169
1 => (
169170
LeadBytes::One,
170-
(&from_text_to_bytes(encoded_value).unwrap()[1..]).to_vec(),
171+
(from_text_to_bytes(encoded_value).unwrap()[1..]).to_vec(),
171172
),
172173
2 => (
173174
LeadBytes::Two,
174-
(&from_text_to_bytes(encoded_value).unwrap()[2..]).to_vec(),
175+
(from_text_to_bytes(encoded_value).unwrap()[2..]).to_vec(),
175176
),
176177
_ => panic!("Invalid leading bytes length"),
177178
};
@@ -264,7 +265,7 @@ impl VariableLengthCode {
264265
LeadBytes::Two => VariableCodeSelector::ShortTwoLeadBytes,
265266
};
266267
let quadlets = adjust_with_num(*length, 2);
267-
format!("{}{}{}", selector.to_string(), code.to_string(), quadlets)
268+
format!("{}{}{}", selector, code, quadlets)
268269
}
269270
VariableLengthCode::Large { lb, code, length } => {
270271
let selector = match lb {
@@ -273,7 +274,7 @@ impl VariableLengthCode {
273274
LeadBytes::Two => VariableCodeSelector::LongTwoLeadBytes,
274275
};
275276
let quadlets = adjust_with_num(*length as u16, 4);
276-
format!("{}{}{}", selector.to_string(), code.to_string(), quadlets)
277+
format!("{}{}{}", selector, code, quadlets)
277278
}
278279
}
279280
}

said/src/bin/sai.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ Supported codes:
8383
}
8484

8585
if matches.contains_id("file") {
86-
let file_path = matches.value_of("file").unwrap();
87-
let file = File::open(file_path).expect("Unable to open file");
88-
let reader = BufReader::new(file);
86+
let file_path = matches.value_of("file").unwrap();
87+
let file = File::open(file_path).expect("Unable to open file");
88+
let reader = BufReader::new(file);
8989

90-
let calculated_sai = hash_algorithm.derive_from_stream(reader);
90+
let calculated_sai = hash_algorithm.derive_from_stream(reader);
9191
match calculated_sai {
9292
Ok(sai) => println!("Calculated SAI: {}", sai.to_str()),
9393
Err(e) => eprintln!("Error calculating SAI: {}", e),

said/src/derivation/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct HashFunction(pub(crate) HashFunctionCode);
1919
impl HashFunction {
2020
#[cfg(feature = "file")]
2121
pub fn digest_from_stream<R: Read>(&self, mut reader: R) -> Result<Vec<u8>, std::io::Error> {
22-
match &self.0 {
22+
match &self.0 {
2323
HashFunctionCode::Blake3_256 => digest::blake3_256_digest_stream(&mut reader),
2424
_ => todo!("Stream digest not implemented for this hash function"),
2525
}
@@ -43,7 +43,10 @@ impl HashFunction {
4343
SelfAddressingIdentifier::new(self.to_owned(), self.digest(data))
4444
}
4545
#[cfg(feature = "file")]
46-
pub fn derive_from_stream<R: Read>(&self, reader: R) -> Result<SelfAddressingIdentifier, std::io::Error> {
46+
pub fn derive_from_stream<R: Read>(
47+
&self,
48+
reader: R,
49+
) -> Result<SelfAddressingIdentifier, std::io::Error> {
4750
let digest = self.digest_from_stream(reader)?;
4851
Ok(SelfAddressingIdentifier::new(self.to_owned(), digest))
4952
}

0 commit comments

Comments
 (0)