Skip to content

Commit

Permalink
Fix Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Feb 3, 2023
1 parent badfde3 commit e8cce73
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 73 deletions.
106 changes: 47 additions & 59 deletions benches/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl CipherSuite for Default {
fn server_setup(c: &mut Criterion) {
let mut rng = OsRng;

c.bench_function(&format!("server setup ({})", SUFFIX), move |b| {
c.bench_function(&format!("server setup ({SUFFIX})"), move |b| {
b.iter(|| {
ServerSetup::<Default>::new(&mut rng);
})
Expand All @@ -49,14 +49,11 @@ fn client_registration_start(c: &mut Criterion) {
let mut rng = OsRng;
let password = b"password";

c.bench_function(
&format!("client registration start ({})", SUFFIX),
move |b| {
b.iter(|| {
ClientRegistration::<Default>::start(&mut rng, password).unwrap();
})
},
);
c.bench_function(&format!("client registration start ({SUFFIX})"), move |b| {
b.iter(|| {
ClientRegistration::<Default>::start(&mut rng, password).unwrap();
})
});
}

fn server_registration_start(c: &mut Criterion) {
Expand All @@ -67,19 +64,16 @@ fn server_registration_start(c: &mut Criterion) {
let client_registration_start_result =
ClientRegistration::<Default>::start(&mut rng, password).unwrap();

c.bench_function(
&format!("server registration start ({})", SUFFIX),
move |b| {
b.iter(|| {
ServerRegistration::<Default>::start(
&server_setup,
client_registration_start_result.message.clone(),
username,
)
.unwrap();
})
},
);
c.bench_function(&format!("server registration start ({SUFFIX})"), move |b| {
b.iter(|| {
ServerRegistration::<Default>::start(
&server_setup,
client_registration_start_result.message.clone(),
username,
)
.unwrap();
})
});
}

fn client_registration_finish(c: &mut Criterion) {
Expand All @@ -97,7 +91,7 @@ fn client_registration_finish(c: &mut Criterion) {
.unwrap();

c.bench_function(
&format!("client registration finish ({})", SUFFIX),
&format!("client registration finish ({SUFFIX})"),
move |b| {
b.iter(|| {
client_registration_start_result
Expand Down Expand Up @@ -139,7 +133,7 @@ fn server_registration_finish(c: &mut Criterion) {
.unwrap();

c.bench_function(
&format!("server registration finish ({})", SUFFIX),
&format!("server registration finish ({SUFFIX})"),
move |b| {
b.iter(|| {
ServerRegistration::finish(client_registration_finish_result.clone().message);
Expand All @@ -152,7 +146,7 @@ fn client_login_start(c: &mut Criterion) {
let mut rng = OsRng;
let password = b"password";

c.bench_function(&format!("client login start ({})", SUFFIX), move |b| {
c.bench_function(&format!("client login start ({SUFFIX})"), move |b| {
b.iter(|| {
ClientLogin::<Default>::start(&mut rng, password).unwrap();
})
Expand Down Expand Up @@ -184,22 +178,19 @@ fn server_login_start_real(c: &mut Criterion) {
let password_file = ServerRegistration::finish(client_registration_finish_result.message);
let client_login_start_result = ClientLogin::<Default>::start(&mut rng, password).unwrap();

c.bench_function(
&format!("server login start (real) ({})", SUFFIX),
move |b| {
b.iter(|| {
ServerLogin::start(
&mut rng,
&server_setup,
Some(password_file.clone()),
client_login_start_result.clone().message,
username,
ServerLoginStartParameters::default(),
)
.unwrap();
})
},
);
c.bench_function(&format!("server login start (real) ({SUFFIX})"), move |b| {
b.iter(|| {
ServerLogin::start(
&mut rng,
&server_setup,
Some(password_file.clone()),
client_login_start_result.clone().message,
username,
ServerLoginStartParameters::default(),
)
.unwrap();
})
});
}

fn server_login_start_fake(c: &mut Criterion) {
Expand All @@ -209,22 +200,19 @@ fn server_login_start_fake(c: &mut Criterion) {
let server_setup = ServerSetup::<Default>::new(&mut rng);
let client_login_start_result = ClientLogin::<Default>::start(&mut rng, password).unwrap();

c.bench_function(
&format!("server login start (fake) ({})", SUFFIX),
move |b| {
b.iter(|| {
ServerLogin::start(
&mut rng,
&server_setup,
None,
client_login_start_result.clone().message,
username,
ServerLoginStartParameters::default(),
)
.unwrap();
})
},
);
c.bench_function(&format!("server login start (fake) ({SUFFIX})"), move |b| {
b.iter(|| {
ServerLogin::start(
&mut rng,
&server_setup,
None,
client_login_start_result.clone().message,
username,
ServerLoginStartParameters::default(),
)
.unwrap();
})
});
}

fn client_login_finish(c: &mut Criterion) {
Expand Down Expand Up @@ -261,7 +249,7 @@ fn client_login_finish(c: &mut Criterion) {
)
.unwrap();

c.bench_function(&format!("client login finish ({})", SUFFIX), move |b| {
c.bench_function(&format!("client login finish ({SUFFIX})"), move |b| {
b.iter(|| {
client_login_start_result
.clone()
Expand Down Expand Up @@ -318,7 +306,7 @@ fn server_login_finish(c: &mut Criterion) {
)
.unwrap();

c.bench_function(&format!("server login finish ({})", SUFFIX), move |b| {
c.bench_function(&format!("server login finish ({SUFFIX})"), move |b| {
b.iter(|| {
server_login_start_result
.clone()
Expand Down
16 changes: 5 additions & 11 deletions examples/digital_locker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,10 @@ fn main() {
&registered_lockers[locker_index],
) {
Ok(contents) => {
println!("\n\nSuccess! Contents: {}\n\n", contents);
println!("\n\nSuccess! Contents: {contents}\n\n");
}
Err(err) => {
println!(
"\n\nError encountered, could not open locker: {}\n\n",
err
);
println!("\n\nError encountered, could not open locker: {err}\n\n");
}
}
}
Expand All @@ -304,10 +301,7 @@ fn display_lockers(lockers: &[Locker]) {
locker_numbers.push(i);
}

println!(
"\nCurrently registered locker numbers: {:?}\n",
locker_numbers
);
println!("\nCurrently registered locker numbers: {locker_numbers:?}\n");
}

// Handle readline errors
Expand All @@ -320,7 +314,7 @@ fn handle_error(err: ReadlineError) {
println!("CTRL-D");
}
err => {
println!("Error: {:?}", err);
println!("Error: {err:?}");
}
}
}
Expand All @@ -333,7 +327,7 @@ fn get_two_strings(
string1: Option<String>,
) -> (String, String) {
let query = if string1.is_none() { s1 } else { s2 };
let readline = rl.readline(&format!("{}: ", query));
let readline = rl.readline(&format!("{query}: "));
match readline {
Ok(line) => match string1 {
Some(x) => (x, line),
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ fn handle_error(err: ReadlineError) {
println!("CTRL-D");
}
err => {
println!("Error: {:?}", err);
println!("Error: {err:?}");
}
}
}
Expand All @@ -241,7 +241,7 @@ fn get_two_strings(
string1: Option<String>,
) -> (String, String) {
let query = if string1.is_none() { s1 } else { s2 };
let readline = rl.readline(&format!("{}: ", query));
let readline = rl.readline(&format!("{query}: "));
match readline {
Ok(line) => match string1 {
Some(x) => (x, line),
Expand Down
2 changes: 1 addition & 1 deletion src/tests/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn parse_params(input: &str) -> String {
let key = iter.next().unwrap().split_whitespace().next().unwrap();
let val = iter.next().unwrap().split_whitespace().next().unwrap();

param = format!(" \"{}\": \"{}", key, val);
param = format!(" \"{key}\": \"{val}");
} else {
let s = line.trim().to_string();
if s.contains('~') || s.contains('#') {
Expand Down

0 comments on commit e8cce73

Please sign in to comment.