Skip to content

Commit 695e390

Browse files
authored
srp: expand lints (#244)
Adds a substantial number of lints and corrects the failures
1 parent 73c8245 commit 695e390

File tree

5 files changed

+59
-14
lines changed

5 files changed

+59
-14
lines changed

srp/src/client.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
use alloc::vec::Vec;
2-
use core::marker::PhantomData;
3-
use crypto_bigint::{BoxedUint, ConcatenatingMul, Odd, Resize, modular::BoxedMontyForm};
4-
use digest::{Digest, Output};
5-
use subtle::ConstantTimeEq;
6-
71
use crate::{
82
Group,
93
errors::AuthError,
@@ -12,6 +6,11 @@ use crate::{
126
monty_form,
137
},
148
};
9+
use alloc::vec::Vec;
10+
use core::marker::PhantomData;
11+
use crypto_bigint::{BoxedUint, ConcatenatingMul, Odd, Resize, modular::BoxedMontyForm};
12+
use digest::{Digest, Output};
13+
use subtle::ConstantTimeEq;
1514

1615
/// SRP client implementation.
1716
///
@@ -112,6 +111,7 @@ use crate::{
112111
/// let pwd_verifier = client.compute_verifier(username, password, salt);
113112
/// send_registration_data(username, salt, &pwd_verifier);
114113
/// ```
114+
#[derive(Debug)]
115115
pub struct Client<G: Group, D: Digest> {
116116
g: BoxedMontyForm,
117117
username_in_x: bool,
@@ -331,6 +331,7 @@ impl<G: Group, D: Digest> Default for Client<G, D> {
331331
/// [RFC5054]-compatible SRP client state after handshake with the server.
332332
///
333333
/// [RFC5054]: https://datatracker.ietf.org/doc/html/rfc5054
334+
#[derive(Debug)]
334335
pub struct ClientVerifier<D: Digest> {
335336
m1: Output<D>,
336337
m2: Output<D>,
@@ -363,6 +364,7 @@ impl<D: Digest> ClientVerifier<D> {
363364

364365
/// Legacy SRP client state after handshake with the server, compatible with `srp` v0.6 and earlier.
365366
#[deprecated(since = "0.7.0", note = "please switch to `ClientVerifierRfc5054`")]
367+
#[derive(Debug)]
366368
pub struct LegacyClientVerifier<D: Digest> {
367369
m1: Output<D>,
368370
m2: Output<D>,

srp/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use core::{error, fmt};
44

55
/// SRP authentication error.
6-
#[derive(Debug, Clone, Eq, PartialEq)]
6+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
77
pub enum AuthError {
88
/// Parameter with the given `name` is illegal.
99
IllegalParameter {

srp/src/groups.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
//! groups. Additionally, it is not recommended to use `G1024` and `G_1536`,
55
//! they are provided only for compatibility with the legacy software.
66
7+
use core::{
8+
any,
9+
fmt::{self, Debug},
10+
};
711
use crypto_bigint::{
812
BoxedUint, Odd, Resize,
913
modular::{BoxedMontyForm, BoxedMontyParams},
@@ -29,12 +33,32 @@ pub trait Group {
2933
macro_rules! define_group {
3034
($name:ident, $g:expr, $n:expr, $doc:expr) => {
3135
#[doc = $doc]
36+
#[derive(Clone, Copy)]
3237
pub struct $name;
3338

3439
impl Group for $name {
3540
const G: u64 = $g;
3641
const N: &'static [u8] = include_bytes!("groups/1024.bin");
3742
}
43+
44+
impl Debug for $name {
45+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46+
let name = any::type_name::<$name>();
47+
let name = name.split("::").last().unwrap_or(name);
48+
49+
write!(f, "{} {{ G: {}, N: 0x", name, Self::G)?;
50+
for byte in Self::N {
51+
write!(f, "{byte:02X}")?;
52+
}
53+
write!(f, " }}")
54+
}
55+
}
56+
57+
impl<Rhs: Group> PartialEq<Rhs> for $name {
58+
fn eq(&self, _other: &Rhs) -> bool {
59+
Self::G == Rhs::G && Self::N == Rhs::N
60+
}
61+
}
3862
};
3963
}
4064

srp/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,24 @@
66
)]
77
#![allow(clippy::many_single_char_names)]
88
#![forbid(unsafe_code)]
9-
#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
9+
#![warn(
10+
clippy::checked_conversions,
11+
clippy::integer_division_remainder_used,
12+
clippy::mod_module_files,
13+
clippy::panic,
14+
clippy::panic_in_result_fn,
15+
clippy::std_instead_of_alloc,
16+
clippy::std_instead_of_core,
17+
clippy::unwrap_used,
18+
missing_copy_implementations,
19+
missing_debug_implementations,
20+
missing_docs,
21+
rust_2018_idioms,
22+
trivial_casts,
23+
trivial_numeric_casts,
24+
unused_lifetimes,
25+
unused_qualifications
26+
)]
1027

1128
//! # Usage
1229
//! See [`Client`] and [`Server`] types for usage information.

srp/src/server.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
use alloc::vec::Vec;
2-
use core::marker::PhantomData;
3-
use crypto_bigint::{BoxedUint, Odd, Resize, modular::BoxedMontyForm};
4-
use digest::{Digest, Output};
5-
use subtle::ConstantTimeEq;
6-
71
use crate::{
82
Group,
93
errors::AuthError,
@@ -12,6 +6,11 @@ use crate::{
126
monty_form,
137
},
148
};
9+
use alloc::vec::Vec;
10+
use core::marker::PhantomData;
11+
use crypto_bigint::{BoxedUint, Odd, Resize, modular::BoxedMontyForm};
12+
use digest::{Digest, Output};
13+
use subtle::ConstantTimeEq;
1514

1615
/// SRP server implementation.
1716
///
@@ -90,6 +89,7 @@ use crate::{
9089
/// let session_key = verifier.verify_client(&client_proof).unwrap();
9190
/// send_proof(verifier.proof());
9291
/// ```
92+
#[derive(Debug)]
9393
pub struct Server<G: Group, D: Digest> {
9494
g: BoxedMontyForm,
9595
d: PhantomData<(G, D)>,
@@ -267,6 +267,7 @@ impl<G: Group, D: Digest> Default for Server<G, D> {
267267
/// [RFC5054] SRP server state after handshake with the client.
268268
///
269269
/// [RFC5054]: https://datatracker.ietf.org/doc/html/rfc5054
270+
#[derive(Debug)]
270271
pub struct ServerVerifier<D: Digest> {
271272
m1: Output<D>,
272273
m2: Output<D>,
@@ -299,6 +300,7 @@ impl<D: Digest> ServerVerifier<D> {
299300

300301
/// Legacy SRP server state after handshake with the client, compatible with `srp` v0.6 and earlier.
301302
#[deprecated(since = "0.7.0", note = "please switch to `ServerVerifierRfc5054`")]
303+
#[derive(Debug)]
302304
pub struct LegacyServerVerifier<D: Digest> {
303305
m1: Output<D>,
304306
m2: Output<D>,

0 commit comments

Comments
 (0)