diff --git a/sasl/src/client/mechanisms/anonymous.rs b/sasl/src/client/mechanisms/anonymous.rs index 96b236a..fbda157 100644 --- a/sasl/src/client/mechanisms/anonymous.rs +++ b/sasl/src/client/mechanisms/anonymous.rs @@ -11,6 +11,7 @@ impl Anonymous { /// /// It is recommended that instead you use a `Credentials` struct and turn it into the /// requested mechanism using `from_credentials`. + #[allow(clippy::new_without_default)] pub fn new() -> Anonymous { Anonymous } diff --git a/sasl/src/client/mechanisms/scram.rs b/sasl/src/client/mechanisms/scram.rs index 90f7260..5d82876 100644 --- a/sasl/src/client/mechanisms/scram.rs +++ b/sasl/src/client/mechanisms/scram.rs @@ -51,7 +51,7 @@ impl Scram { password: password.into(), client_nonce: generate_nonce()?, state: ScramState::Init, - channel_binding: channel_binding, + channel_binding, _marker: PhantomData, }) } @@ -112,7 +112,7 @@ impl Mechanism for Scram { data.extend(&bare); self.state = ScramState::SentInitialMessage { initial_message: bare, - gs2_header: gs2_header, + gs2_header, }; data } @@ -130,9 +130,9 @@ impl Mechanism for Scram { let server_nonce = frame.get("r"); let salt = frame.get("s").and_then(|v| Base64.decode(v).ok()); let iterations = frame.get("i").and_then(|v| v.parse().ok()); - let server_nonce = server_nonce.ok_or_else(|| MechanismError::NoServerNonce)?; - let salt = salt.ok_or_else(|| MechanismError::NoServerSalt)?; - let iterations = iterations.ok_or_else(|| MechanismError::NoServerIterations)?; + let server_nonce = server_nonce.ok_or(MechanismError::NoServerNonce)?; + let salt = salt.ok_or(MechanismError::NoServerSalt)?; + let iterations = iterations.ok_or(MechanismError::NoServerIterations)?; // TODO: SASLprep let mut client_final_message_bare = Vec::new(); client_final_message_bare.extend(b"c="); @@ -158,10 +158,8 @@ impl Mechanism for Scram { let mut client_final_message = Vec::new(); client_final_message.extend(&client_final_message_bare); client_final_message.extend(b",p="); - client_final_message.extend(Base64.encode(&client_proof).bytes()); - next_state = ScramState::GotServerData { - server_signature: server_signature, - }; + client_final_message.extend(Base64.encode(client_proof).bytes()); + next_state = ScramState::GotServerData { server_signature }; ret = client_final_message; } _ => { @@ -178,7 +176,7 @@ impl Mechanism for Scram { ScramState::GotServerData { ref server_signature, } => { - if let Some(sig) = frame.get("v").and_then(|v| Base64.decode(&v).ok()) { + if let Some(sig) = frame.get("v").and_then(|v| Base64.decode(v).ok()) { if sig == *server_signature { Ok(()) } else { diff --git a/sasl/src/common/mod.rs b/sasl/src/common/mod.rs index a43cf2e..dd6d854 100644 --- a/sasl/src/common/mod.rs +++ b/sasl/src/common/mod.rs @@ -86,9 +86,9 @@ impl Secret { ) -> Secret { Secret::Password(Password::Pbkdf2 { method: method.into(), - salt: salt, - iterations: iterations, - data: data, + salt, + iterations, + data, }) } } @@ -135,7 +135,7 @@ fn xor_works() { pub fn xor(a: &[u8], b: &[u8]) -> Vec { assert_eq!(a.len(), b.len()); let mut ret = Vec::with_capacity(a.len()); - for (a, b) in a.into_iter().zip(b) { + for (a, b) in a.iter().zip(b) { ret.push(a ^ b); } ret @@ -149,11 +149,8 @@ pub fn parse_frame(frame: &[u8]) -> Result, FromUtf8Erro let mut tmp = s.splitn(2, '='); let key = tmp.next(); let val = tmp.next(); - match (key, val) { - (Some(k), Some(v)) => { - ret.insert(k.to_owned(), v.to_owned()); - } - _ => (), + if let (Some(k), Some(v)) = (key, val) { + ret.insert(k.to_owned(), v.to_owned()); } } Ok(ret) diff --git a/sasl/src/common/scram.rs b/sasl/src/common/scram.rs index c899aff..689a4d7 100644 --- a/sasl/src/common/scram.rs +++ b/sasl/src/common/scram.rs @@ -14,7 +14,7 @@ use base64::{engine::general_purpose::STANDARD as Base64, Engine}; pub fn generate_nonce() -> Result { let mut data = [0u8; 32]; getrandom(&mut data)?; - Ok(Base64.encode(&data)) + Ok(Base64.encode(data)) } #[derive(Debug, PartialEq)] @@ -111,7 +111,7 @@ impl ScramProvider for Sha1 { method.to_string(), Self::name().to_string(), )) - } else if my_salt == &salt { + } else if my_salt == salt { Err(DeriveError::IncorrectSalt) } else if my_iterations == iterations { Err(DeriveError::IncompatibleIterationCount( @@ -171,7 +171,7 @@ impl ScramProvider for Sha256 { method.to_string(), Self::name().to_string(), )) - } else if my_salt == &salt { + } else if my_salt == salt { Err(DeriveError::IncorrectSalt) } else if my_iterations == iterations { Err(DeriveError::IncompatibleIterationCount( diff --git a/sasl/src/secret.rs b/sasl/src/secret.rs index 0ce57a7..fe49d00 100644 --- a/sasl/src/secret.rs +++ b/sasl/src/secret.rs @@ -30,8 +30,8 @@ impl Pbkdf2Sha1 { let digest = Sha1::derive(&Password::Plain(password.to_owned()), salt, iterations)?; Ok(Pbkdf2Sha1 { salt: salt.to_vec(), - iterations: iterations, - digest: digest, + iterations, + digest, }) } } @@ -70,8 +70,8 @@ impl Pbkdf2Sha256 { let digest = Sha256::derive(&Password::Plain(password.to_owned()), salt, iterations)?; Ok(Pbkdf2Sha256 { salt: salt.to_vec(), - iterations: iterations, - digest: digest, + iterations, + digest, }) } } diff --git a/sasl/src/server/mechanisms/anonymous.rs b/sasl/src/server/mechanisms/anonymous.rs index 5a5381e..9203167 100644 --- a/sasl/src/server/mechanisms/anonymous.rs +++ b/sasl/src/server/mechanisms/anonymous.rs @@ -6,6 +6,7 @@ use getrandom::getrandom; pub struct Anonymous; impl Anonymous { + #[allow(clippy::new_without_default)] pub fn new() -> Anonymous { Anonymous } diff --git a/sasl/src/server/mechanisms/plain.rs b/sasl/src/server/mechanisms/plain.rs index 79d090f..eae74a1 100644 --- a/sasl/src/server/mechanisms/plain.rs +++ b/sasl/src/server/mechanisms/plain.rs @@ -8,9 +8,7 @@ pub struct Plain> { impl> Plain { pub fn new(validator: V) -> Plain { - Plain { - validator: validator, - } + Plain { validator } } } @@ -22,14 +20,10 @@ impl> Mechanism for Plain { fn respond(&mut self, payload: &[u8]) -> Result { let mut sp = payload.split(|&b| b == 0); sp.next(); - let username = sp - .next() - .ok_or_else(|| MechanismError::NoUsernameSpecified)?; + let username = sp.next().ok_or(MechanismError::NoUsernameSpecified)?; let username = String::from_utf8(username.to_vec()) .map_err(|_| MechanismError::ErrorDecodingUsername)?; - let password = sp - .next() - .ok_or_else(|| MechanismError::NoPasswordSpecified)?; + let password = sp.next().ok_or(MechanismError::NoPasswordSpecified)?; let password = String::from_utf8(password.to_vec()) .map_err(|_| MechanismError::ErrorDecodingPassword)?; let ident = Identity::Username(username); diff --git a/sasl/src/server/mechanisms/scram.rs b/sasl/src/server/mechanisms/scram.rs index 09a4fc9..af0e410 100644 --- a/sasl/src/server/mechanisms/scram.rs +++ b/sasl/src/server/mechanisms/scram.rs @@ -44,8 +44,8 @@ where Scram { name: format!("SCRAM-{}", S::name()), state: ScramState::Init, - channel_binding: channel_binding, - provider: provider, + channel_binding, + provider, _marker: PhantomData, } } @@ -108,9 +108,9 @@ where } let frame = parse_frame(&rest).map_err(|_| MechanismError::CannotDecodeInitialMessage)?; - let username = frame.get("n").ok_or_else(|| MechanismError::NoUsername)?; + let username = frame.get("n").ok_or(MechanismError::NoUsername)?; let identity = Identity::Username(username.to_owned()); - let client_nonce = frame.get("r").ok_or_else(|| MechanismError::NoNonce)?; + let client_nonce = frame.get("r").ok_or(MechanismError::NoNonce)?; let mut server_nonce = String::new(); server_nonce += client_nonce; server_nonce += @@ -125,12 +125,12 @@ where buf.extend(pbkdf2.iterations().to_string().bytes()); ret = Response::Proceed(buf.clone()); next_state = ScramState::SentChallenge { - server_nonce: server_nonce, - identity: identity, + server_nonce, + identity, salted_password: pbkdf2.digest().to_vec(), initial_client_message: rest, initial_server_message: buf, - gs2_header: gs2_header, + gs2_header, }; } ScramState::SentChallenge { @@ -151,8 +151,8 @@ where client_final_message_bare.extend(Base64.encode(&cb_data).bytes()); client_final_message_bare.extend(b",r="); client_final_message_bare.extend(server_nonce.bytes()); - let client_key = S::hmac(b"Client Key", &salted_password)?; - let server_key = S::hmac(b"Server Key", &salted_password)?; + let client_key = S::hmac(b"Client Key", salted_password)?; + let server_key = S::hmac(b"Server Key", salted_password)?; let mut auth_message = Vec::new(); auth_message.extend(initial_client_message); auth_message.extend(b","); @@ -162,7 +162,7 @@ where let stored_key = S::hash(&client_key); let client_signature = S::hmac(&auth_message, &stored_key)?; let client_proof = xor(&client_key, &client_signature); - let sent_proof = frame.get("p").ok_or_else(|| MechanismError::NoProof)?; + let sent_proof = frame.get("p").ok_or(MechanismError::NoProof)?; let sent_proof = Base64 .decode(sent_proof) .map_err(|_| MechanismError::CannotDecodeProof)?; @@ -172,7 +172,7 @@ where let server_signature = S::hmac(&auth_message, &server_key)?; let mut buf = Vec::new(); buf.extend(b"v="); - buf.extend(Base64.encode(&server_signature).bytes()); + buf.extend(Base64.encode(server_signature).bytes()); ret = Response::Success(identity.clone(), buf); next_state = ScramState::Done; }