From d1af19f5f03370684cb29a312ab0ba720bc51bc8 Mon Sep 17 00:00:00 2001 From: moznion Date: Tue, 24 Nov 2020 01:50:57 +0900 Subject: [PATCH] Fix clippy warnings --- src/attribute.rs | 10 +++++----- src/attributes.rs | 2 +- src/client.rs | 4 ++-- src/packet.rs | 16 ++++++++-------- src/server.rs | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/attribute.rs b/src/attribute.rs index dbcc1af..e80969f 100644 --- a/src/attribute.rs +++ b/src/attribute.rs @@ -8,11 +8,11 @@ use chrono::{DateTime, Utc, TimeZone}; pub struct Attribute(pub(crate) Vec); impl Attribute { - pub fn from_integer32(v: &u32) -> Self { - Attribute(u32::to_be_bytes(*v).to_vec()) + pub fn from_integer32(v: u32) -> Self { + Attribute(u32::to_be_bytes(v).to_vec()) } - pub fn from_string(v: &String) -> Self { + pub fn from_string(v: &str) -> Self { Attribute(v.as_bytes().to_vec()) } @@ -33,7 +33,7 @@ impl Attribute { return Err("the length of plain_text has to be within 128, but the given value is longer".to_owned()); } - if secret.len() == 0 { + if secret.is_empty() { return Err("secret hasn't be empty, but the given value is empty".to_owned()); } @@ -127,7 +127,7 @@ impl Attribute { return Err(format!("invalid attribute length {}", self.0.len())); } - if secret.len() == 0 { + if secret.is_empty() { return Err("secret hasn't be empty, but the given value is empty".to_owned()); } diff --git a/src/attributes.rs b/src/attributes.rs index c49e4bc..fe011e9 100644 --- a/src/attributes.rs +++ b/src/attributes.rs @@ -81,6 +81,6 @@ impl Attributes { encoded = encoded[size..].to_owned(); } - return encoded; + encoded } } diff --git a/src/client.rs b/src/client.rs index 8a2c386..f4ddb46 100644 --- a/src/client.rs +++ b/src/client.rs @@ -47,7 +47,7 @@ impl Client { let request_data = match request_packet.encode() { Ok(encoded) => encoded, - Err(e) => return Err(FailedRadiusPacketEncoding(e.to_string())) + Err(e) => return Err(FailedRadiusPacketEncoding(e)) }; match conn.send(request_data.as_slice()).await { @@ -63,7 +63,7 @@ impl Client { match Packet::parse(&buf[..len].to_vec(), request_packet.get_secret()) { Ok(response_packet) => Ok(response_packet), - Err(e) => Err(FailedParsingUDPResponse(e.to_string())) + Err(e) => Err(FailedParsingUDPResponse(e)) } } } diff --git a/src/packet.rs b/src/packet.rs index 1e65e15..2f62d9c 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -64,9 +64,9 @@ impl Packet { }) } - pub fn response(&self, code: &Code) -> Self { + pub fn response(&self, code: Code) -> Self { Packet { - code: code.clone(), + code, identifier: self.identifier, authenticator: self.authenticator.clone(), secret: self.secret.clone(), @@ -77,7 +77,7 @@ impl Packet { pub fn encode(&self) -> Result, String> { let bs = match self.marshal_binary() { Ok(bs) => bs, - Err(e) => return Err(e.to_string()), + Err(e) => return Err(e), }; match self.code { @@ -107,7 +107,7 @@ impl Packet { pub fn marshal_binary(&self) -> Result, String> { let attributes_len = match self.attributes.attributes_encoded_len() { Ok(attributes_len) => attributes_len, - Err(e) => return Err(e.to_string()) + Err(e) => return Err(e) }; let size = 20 + attributes_len; @@ -116,7 +116,7 @@ impl Packet { } let mut bs: Vec = Vec::new(); - bs.push(self.code.clone() as u8); + bs.push(self.code as u8); bs.push(self.identifier); bs.extend(u16::to_be_bytes(size).to_vec()); bs.extend(self.authenticator.to_vec()); @@ -124,7 +124,7 @@ impl Packet { } pub fn is_authentic_response(response: Vec, request: Vec, secret: Vec) -> bool { - if response.len() < 20 || request.len() < 20 || secret.len() == 0 { + if response.len() < 20 || request.len() < 20 || secret.is_empty() { return false; } @@ -137,7 +137,7 @@ impl Packet { } pub fn is_authentic_request(request: &[u8], secret: &[u8]) -> bool { - if request.len() < 20 || secret.len() == 0 { + if request.len() < 20 || secret.is_empty() { return false; } @@ -146,7 +146,7 @@ impl Packet { Code::AccountingRequest | Code::DisconnectRequest | Code::CoARequest => { md5::compute([ &request[..4], - &vec![ + &[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ], diff --git a/src/server.rs b/src/server.rs index 65052db..4077ba5 100644 --- a/src/server.rs +++ b/src/server.rs @@ -88,7 +88,7 @@ impl Server { async fn process_request( conn: Arc, - request_data: &Vec, // TODO + request_data: &[u8], local_addr: SocketAddr, remote_addr: SocketAddr, undergoing_requests_lock: Arc>>, @@ -103,7 +103,7 @@ impl Server { return; } }; - if secret.len() == 0 { + if secret.is_empty() { error!("empty secret returned from secret source; empty secret is prohibited"); return; }