Fix clippy warnings

This commit is contained in:
moznion
2020-11-24 01:50:57 +09:00
parent d0a954fc6e
commit d1af19f5f0
5 changed files with 18 additions and 18 deletions

View File

@@ -8,11 +8,11 @@ use chrono::{DateTime, Utc, TimeZone};
pub struct Attribute(pub(crate) Vec<u8>);
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());
}

View File

@@ -81,6 +81,6 @@ impl Attributes {
encoded = encoded[size..].to_owned();
}
return encoded;
encoded
}
}

View File

@@ -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))
}
}
}

View File

@@ -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<Vec<u8>, 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<Vec<u8>, 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<u8> = 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<u8>, request: Vec<u8>, secret: Vec<u8>) -> 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,
],

View File

@@ -88,7 +88,7 @@ impl Server {
async fn process_request<T: RequestHandler, U: SecretProvider>(
conn: Arc<UdpSocket>,
request_data: &Vec<u8>, // TODO
request_data: &[u8],
local_addr: SocketAddr,
remote_addr: SocketAddr,
undergoing_requests_lock: Arc<RwLock<HashSet<RequestKey>>>,
@@ -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;
}