From 48a60083bb0ae4728fe4fbd6808d77a2afe57596 Mon Sep 17 00:00:00 2001 From: Mikael Hermansson <7b4software@proton.me> Date: Fri, 3 Feb 2023 21:58:08 +0100 Subject: [PATCH] Fix clippy warnings and bump to edition 2021 --- code-generator/Cargo.toml | 2 +- code-generator/src/main.rs | 88 ++++++++--------------------------- examples/Cargo.toml | 2 +- radius/Cargo.toml | 2 +- radius/src/client.rs | 10 +--- radius/src/core/attributes.rs | 16 ++----- radius/src/core/avp.rs | 16 +++---- radius/src/core/packet.rs | 31 +++++------- radius/src/core/rfc2865.rs | 16 +++---- radius/src/core/rfc2866.rs | 6 +-- radius/src/core/rfc2868.rs | 8 +--- radius/src/core/rfc2869.rs | 4 +- radius/src/core/rfc3576.rs | 2 +- radius/src/core/rfc4675.rs | 2 +- radius/src/core/rfc5607.rs | 7 +-- radius/src/core/rfc6677.rs | 2 +- radius/src/server.rs | 4 +- 17 files changed, 69 insertions(+), 149 deletions(-) diff --git a/code-generator/Cargo.toml b/code-generator/Cargo.toml index 11ac7a3..72b15c4 100644 --- a/code-generator/Cargo.toml +++ b/code-generator/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "code-generator" version = "0.3.1" -edition = "2018" +edition = "2021" license-file = "../LICENSE" publish = false diff --git a/code-generator/src/main.rs b/code-generator/src/main.rs index ea91a54..08adeca 100644 --- a/code-generator/src/main.rs +++ b/code-generator/src/main.rs @@ -41,6 +41,7 @@ struct RadiusValue { value: u16, } +#[allow(clippy::upper_case_acronyms)] #[derive(Debug, PartialEq)] enum RadiusAttributeValueType { String, @@ -79,7 +80,7 @@ impl FromStr for RadiusAttributeValueType { } fn print_usage(program: &str, opts: &Options) { - let brief = format!("Usage: {} [options] DICT_FILE OUT_FILE", program); + let brief = format!("Usage: {program} [options] DICT_FILE OUT_FILE"); print!("{}", opts.usage(&brief)); process::exit(0); } @@ -104,9 +105,7 @@ fn main() { "[mandatory] a directory to out the generated code", "/path/to/out/", ); - let matches = opts - .parse(&args[1..]) - .unwrap_or_else(|f| panic!(f.to_string())); + let matches = opts.parse(&args[1..]).unwrap_or_else(|f| panic!("{}", f)); if matches.opt_present("h") { print_usage(&program, &opts); @@ -121,7 +120,7 @@ fn main() { let mut dict_file_paths: Vec<&Path> = matches .free .iter() - .map(|file_path_str| Path::new(file_path_str)) + .map(Path::new) .filter(|path| { if !path.exists() || !path.is_file() { panic!("no such dictionary file => {}", path.to_str().unwrap()); @@ -143,7 +142,7 @@ fn main() { .collect::>(); let rfc_name = dict_file_path.extension().unwrap().to_str().unwrap(); - let mut w = BufWriter::new(File::create(out_dir.join(format!("{}.rs", rfc_name))).unwrap()); + let mut w = BufWriter::new(File::create(out_dir.join(format!("{rfc_name}.rs"))).unwrap()); generate_header(&mut w, &rfc_names, rfc_name, dict_file_lines); generate_attributes_code(&mut w, &radius_attributes, &value_defined_attributes_set); @@ -195,7 +194,7 @@ use crate::core::tag::Tag; w.write_all(code.as_bytes()).unwrap(); for rfc_name in rfc_names { - w.write_all(format!("use crate::core::{};\n", rfc_name).as_bytes()) + w.write_all(format!("use crate::core::{rfc_name};\n").as_bytes()) .unwrap(); } } @@ -219,15 +218,8 @@ fn generate_values_for_attribute_code( let type_name = attr.to_pascal_case(); if maybe_rfc_name.is_none() { - w.write_all( - format!( - "\npub type {type_name} = {radius_value_type};\n", - type_name = type_name, - radius_value_type = RADIUS_VALUE_TYPE - ) - .as_bytes(), - ) - .unwrap(); + w.write_all(format!("\npub type {type_name} = {RADIUS_VALUE_TYPE};\n").as_bytes()) + .unwrap(); } for v in values { @@ -267,7 +259,7 @@ fn generate_attributes_code( value_defined_attributes_set: &HashSet<&String>, ) { for attr in attrs { - generate_attribute_code(w, attr, &value_defined_attributes_set); + generate_attribute_code(w, attr, value_defined_attributes_set); } } @@ -429,8 +421,6 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, AV Ok(vec) }} ", - method_identifier = method_identifier, - type_identifier = type_identifier, ); w.write_all(code.as_bytes()).unwrap(); } @@ -460,8 +450,6 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result Result>, A }} Ok(vec) }} -", - method_identifier = method_identifier, - type_identifier = type_identifier, - ); +"); w.write_all(code.as_bytes()).unwrap(); } @@ -523,10 +508,7 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, T }} Ok(vec) }} -", - method_identifier = method_identifier, - type_identifier = type_identifier, - ); +"); w.write_all(code.as_bytes()).unwrap(); } @@ -554,10 +536,7 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Vec> {{ }} vec }} -", - method_identifier = method_identifier, - type_identifier = type_identifier, - ); +"); w.write_all(code.as_bytes()).unwrap(); } @@ -585,9 +564,7 @@ pub fn lookup_{method_identifier}(packet: &Packet) -> Option> {{ }})), }} }} -", - method_identifier = method_identifier, - type_identifier = type_identifier, +" ); w.write_all(code.as_bytes()).unwrap(); } @@ -621,10 +598,7 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Vec> {{ }} vec }} -", - method_identifier = method_identifier, - type_identifier = type_identifier, - fixed_octets_length = fixed_octets_length, +" ); w.write_all(code.as_bytes()).unwrap(); } @@ -653,9 +627,7 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, }} Ok(vec) }} -", - method_identifier = method_identifier, - type_identifier = type_identifier, +" ); w.write_all(code.as_bytes()).unwrap(); } @@ -686,8 +658,6 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result>, A Ok(vec) }} ", - method_identifier = method_identifier, - type_identifier = type_identifier, ); w.write_all(code.as_bytes()).unwrap(); } @@ -717,8 +687,6 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, Ok(vec) }} ", - method_identifier = method_identifier, - type_identifier = type_identifier, ); w.write_all(code.as_bytes()).unwrap(); } @@ -749,8 +717,6 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result>, A Ok(vec) }} ", - method_identifier = method_identifier, - type_identifier = type_identifier, ); w.write_all(code.as_bytes()).unwrap(); } @@ -780,8 +746,6 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result Result, AVPEr Ok(vec) }} ", - method_identifier = method_identifier, - type_identifier = type_identifier, ); w.write_all(code.as_bytes()).unwrap(); } @@ -842,8 +804,6 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result Ok(vec) }} ", - method_identifier = method_identifier, - type_identifier = type_identifier, ); w.write_all(code.as_bytes()).unwrap(); } @@ -857,7 +817,7 @@ fn generate_value_defined_integer_attribute_code( let code = format!( "/// Add `{method_identifier}` value-defined integer value to a packet. pub fn add_{method_identifier}(packet: &mut Packet, value: {value_type}) {{ - packet.add(AVP::from_u32({type_identifier}, value as u32)); + packet.add(AVP::from_u32({type_identifier}, value)); }} /// Lookup a `{method_identifier}` value-defined integer value from a packet. /// @@ -874,9 +834,6 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result, value: {value_type}) {{ - packet.add(AVP::from_tagged_u32({type_identifier}, tag, value as u32)); + packet.add(AVP::from_tagged_u32({type_identifier}, tag, value)); }} /// Lookup a `{method_identifier}` tagged value-defined integer value from a packet. /// @@ -910,10 +867,7 @@ pub fn lookup_all_{method_identifier}(packet: &Packet) -> Result Result, AVPEr }} Ok(vec) }} -", - method_identifier = method_identifier, - type_identifier = type_identifier, +" ); w.write_all(code.as_bytes()).unwrap(); } @@ -1068,7 +1020,7 @@ fn parse_dict_file( } }; } - _ => return Err(format!("unexpected kind has come => {}", kind)), + _ => return Err(format!("unexpected kind has come => {kind}")), } } diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 078291e..66cfe2f 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -2,7 +2,7 @@ name = "examples" version = "0.3.1" publish = false -edition = "2018" +edition = "2021" license-file = "../LICENSE" repository = "https://github.com/moznion/radius-rs" diff --git a/radius/Cargo.toml b/radius/Cargo.toml index fb26ff3..8734594 100644 --- a/radius/Cargo.toml +++ b/radius/Cargo.toml @@ -2,7 +2,7 @@ name = "radius" version = "0.3.1" authors = ["moznion "] -edition = "2018" +edition = "2021" description = "An async/await native implementation of the RADIUS server and client for Rust." license = "MIT" readme = "../README.md" diff --git a/radius/src/client.rs b/radius/src/client.rs index ccdb55c..d7c3097 100644 --- a/radius/src/client.rs +++ b/radius/src/client.rs @@ -103,12 +103,7 @@ impl Client { let request_data = match request_packet.encode() { Ok(encoded) => encoded, - Err(e) => { - return Err(ClientError::FailedRadiusPacketEncodingError(format!( - "{:?}", - e - ))) - } + Err(e) => return Err(ClientError::FailedRadiusPacketEncodingError(format!("{e}"))), }; let response = match self.socket_timeout { @@ -129,8 +124,7 @@ impl Client { match Packet::decode(&response.to_vec(), request_packet.get_secret()) { Ok(response_packet) => Ok(response_packet), Err(e) => Err(ClientError::FailedDecodingRadiusResponseError(format!( - "{:?}", - e + "{e}" ))), } } diff --git a/radius/src/core/attributes.rs b/radius/src/core/attributes.rs index 841e38f..89f3f4d 100644 --- a/radius/src/core/attributes.rs +++ b/radius/src/core/attributes.rs @@ -14,7 +14,7 @@ impl Attributes { } let length = bs[i + 1] as usize; - if length > bs[i..].len() || length < 2 || length > 255 { + if length > bs[i..].len() || !(2..=255).contains(&length) { return Err("invalid attribute length".to_owned()); } @@ -42,21 +42,11 @@ impl Attributes { } pub(crate) fn del(&mut self, typ: AVPType) { - self.0 = self - .0 - .iter() - .filter(|&avp| avp.typ != typ) - .cloned() - .collect(); + self.0.retain(|avp| avp.typ != typ); } pub(crate) fn lookup(&self, typ: AVPType) -> Option<&AVP> { - self.0.iter().find_map(|avp| { - if avp.typ == typ { - return Some(avp); - } - None - }) + self.0.iter().find(|avp| avp.typ == typ) } pub(crate) fn lookup_all(&self, typ: AVPType) -> Vec<&AVP> { diff --git a/radius/src/core/avp.rs b/radius/src/core/avp.rs index 7dde82e..f2407d8 100644 --- a/radius/src/core/avp.rs +++ b/radius/src/core/avp.rs @@ -339,7 +339,7 @@ impl AVP { const U32_SIZE: usize = std::mem::size_of::(); if self.value.len() != U32_SIZE { return Err(AVPError::InvalidAttributeLengthError( - format!("{} bytes", U32_SIZE), + format!("{U32_SIZE} bytes"), self.value.len(), )); } @@ -356,7 +356,7 @@ impl AVP { const U16_SIZE: usize = std::mem::size_of::(); if self.value.len() != U16_SIZE { return Err(AVPError::InvalidAttributeLengthError( - format!("{} bytes", U16_SIZE), + format!("{U16_SIZE} bytes"), self.value.len(), )); } @@ -453,7 +453,7 @@ impl AVP { const IPV4_SIZE: usize = std::mem::size_of::(); if self.value.len() != IPV4_SIZE { return Err(AVPError::InvalidAttributeLengthError( - format!("{} bytes", IPV4_SIZE), + format!("{IPV4_SIZE} bytes"), self.value.len(), )); } @@ -481,7 +481,7 @@ impl AVP { const IPV6_SIZE: usize = std::mem::size_of::(); if self.value.len() != IPV6_SIZE { return Err(AVPError::InvalidAttributeLengthError( - format!("{} bytes", IPV6_SIZE), + format!("{IPV6_SIZE} bytes"), self.value.len(), )); } @@ -556,7 +556,7 @@ impl AVP { const U32_SIZE: usize = std::mem::size_of::(); if self.value.len() != U32_SIZE { return Err(AVPError::InvalidAttributeLengthError( - format!("{}", U32_SIZE), + format!("{U32_SIZE}"), self.value.len(), )); } @@ -565,7 +565,7 @@ impl AVP { match int_bytes.try_into() { Ok(boxed_array) => { let timestamp = u32::from_be_bytes(boxed_array); - Ok(Utc.timestamp(timestamp as i64, 0)) + Ok(Utc.timestamp_opt(timestamp as i64, 0).unwrap()) } Err(e) => Err(AVPError::DecodingError(e.to_string())), } @@ -725,7 +725,7 @@ mod tests { struct TestCase<'a> { plain_text: &'a str, expected_encoded_len: usize, - }; + } let test_cases = &[ TestCase { @@ -791,7 +791,7 @@ mod tests { struct TestCase<'a> { plain_text: &'a str, expected_encoded_len: usize, - }; + } let test_cases = &[ TestCase { diff --git a/radius/src/core/packet.rs b/radius/src/core/packet.rs index 5c9a718..a756267 100644 --- a/radius/src/core/packet.rs +++ b/radius/src/core/packet.rs @@ -133,7 +133,7 @@ impl Packet { )); } - let attributes = match Attributes::decode(&bs[RADIUS_PACKET_HEADER_LENGTH..len].to_vec()) { + let attributes = match Attributes::decode(&bs[RADIUS_PACKET_HEADER_LENGTH..len]) { Ok(attributes) => attributes, Err(e) => return Err(PacketError::DecodingError(e)), }; @@ -255,7 +255,7 @@ impl Packet { &response[..4], &request[4..RADIUS_PACKET_HEADER_LENGTH], &response[RADIUS_PACKET_HEADER_LENGTH..], - &secret, + secret, ] .concat(), ) @@ -279,7 +279,7 @@ impl Packet { 0x00, 0x00, 0x00, 0x00, ], &request[RADIUS_PACKET_HEADER_LENGTH..], - &secret, + secret, ] .concat(), ) @@ -366,7 +366,7 @@ mod tests { 3 ); assert_eq!(request_packet.encode().unwrap(), request); - assert_eq!(Packet::is_authentic_request(&request, &secret), true); + assert!(Packet::is_authentic_request(&request, &secret)); let response: Vec = vec![ 0x02, 0x00, 0x00, 0x26, 0x86, 0xfe, 0x22, 0x0e, 0x76, 0x24, 0xba, 0x2a, 0x10, 0x05, @@ -378,21 +378,12 @@ mod tests { rfc2865::add_login_service(&mut response_packet, rfc2865::LOGIN_SERVICE_TELNET); rfc2865::add_login_ip_host(&mut response_packet, &Ipv4Addr::from([192, 168, 1, 3])); assert_eq!(response_packet.encode().unwrap(), response); - assert_eq!( - Packet::is_authentic_response(&response, &request, &secret), - true - ); + assert!(Packet::is_authentic_response(&response, &request, &secret)); // test removing a AVP - assert_eq!( - rfc2865::lookup_service_type(&response_packet).is_some(), - true - ); + assert!(rfc2865::lookup_service_type(&response_packet).is_some()); rfc2865::delete_service_type(&mut response_packet); - assert_eq!( - rfc2865::lookup_service_type(&response_packet).is_some(), - false - ); + assert!(rfc2865::lookup_service_type(&response_packet).is_none()); Ok(()) } @@ -520,7 +511,7 @@ mod tests { struct TestCase<'a> { plain_text: &'a str, expected_error: PacketError, - }; + } let test_cases = &[ TestCase { @@ -548,7 +539,7 @@ mod tests { let secret = b"12345"; for test_case in test_cases { let result = Packet::decode(test_case.plain_text.as_bytes(), secret); - assert_eq!(result.is_err(), true); + assert!(result.is_err()); assert_eq!(result.err().unwrap(), test_case.expected_error); } } @@ -561,7 +552,7 @@ mod tests { value: vec![1; 253], }); let encoded = packet.encode(); - assert_eq!(encoded.is_err(), false); + assert!(encoded.is_ok()); let mut packet = Packet::new(Code::AccessRequest, b"12345"); packet.add(AVP { @@ -569,7 +560,7 @@ mod tests { value: vec![1; 254], }); let encoded = packet.encode(); - assert_eq!(encoded.is_err(), true); + assert!(encoded.is_err()); assert_eq!( encoded.err().unwrap(), PacketError::EncodingError("attribute is too large".to_owned()), diff --git a/radius/src/core/rfc2865.rs b/radius/src/core/rfc2865.rs index af54c50..d79c8b8 100644 --- a/radius/src/core/rfc2865.rs +++ b/radius/src/core/rfc2865.rs @@ -286,7 +286,7 @@ pub fn delete_service_type(packet: &mut Packet) { } /// Add `service_type` value-defined integer value to a packet. pub fn add_service_type(packet: &mut Packet, value: ServiceType) { - packet.add(AVP::from_u32(SERVICE_TYPE_TYPE, value as u32)); + packet.add(AVP::from_u32(SERVICE_TYPE_TYPE, value)); } /// Lookup a `service_type` value-defined integer value from a packet. /// @@ -312,7 +312,7 @@ pub fn delete_framed_protocol(packet: &mut Packet) { } /// Add `framed_protocol` value-defined integer value to a packet. pub fn add_framed_protocol(packet: &mut Packet, value: FramedProtocol) { - packet.add(AVP::from_u32(FRAMED_PROTOCOL_TYPE, value as u32)); + packet.add(AVP::from_u32(FRAMED_PROTOCOL_TYPE, value)); } /// Lookup a `framed_protocol` value-defined integer value from a packet. /// @@ -390,7 +390,7 @@ pub fn delete_framed_routing(packet: &mut Packet) { } /// Add `framed_routing` value-defined integer value to a packet. pub fn add_framed_routing(packet: &mut Packet, value: FramedRouting) { - packet.add(AVP::from_u32(FRAMED_ROUTING_TYPE, value as u32)); + packet.add(AVP::from_u32(FRAMED_ROUTING_TYPE, value)); } /// Lookup a `framed_routing` value-defined integer value from a packet. /// @@ -464,7 +464,7 @@ pub fn delete_framed_compression(packet: &mut Packet) { } /// Add `framed_compression` value-defined integer value to a packet. pub fn add_framed_compression(packet: &mut Packet, value: FramedCompression) { - packet.add(AVP::from_u32(FRAMED_COMPRESSION_TYPE, value as u32)); + packet.add(AVP::from_u32(FRAMED_COMPRESSION_TYPE, value)); } /// Lookup a `framed_compression` value-defined integer value from a packet. /// @@ -514,7 +514,7 @@ pub fn delete_login_service(packet: &mut Packet) { } /// Add `login_service` value-defined integer value to a packet. pub fn add_login_service(packet: &mut Packet, value: LoginService) { - packet.add(AVP::from_u32(LOGIN_SERVICE_TYPE, value as u32)); + packet.add(AVP::from_u32(LOGIN_SERVICE_TYPE, value)); } /// Lookup a `login_service` value-defined integer value from a packet. /// @@ -540,7 +540,7 @@ pub fn delete_login_tcp_port(packet: &mut Packet) { } /// Add `login_tcp_port` value-defined integer value to a packet. pub fn add_login_tcp_port(packet: &mut Packet, value: LoginTCPPort) { - packet.add(AVP::from_u32(LOGIN_TCP_PORT_TYPE, value as u32)); + packet.add(AVP::from_u32(LOGIN_TCP_PORT_TYPE, value)); } /// Lookup a `login_tcp_port` value-defined integer value from a packet. /// @@ -792,7 +792,7 @@ pub fn delete_termination_action(packet: &mut Packet) { } /// Add `termination_action` value-defined integer value to a packet. pub fn add_termination_action(packet: &mut Packet, value: TerminationAction) { - packet.add(AVP::from_u32(TERMINATION_ACTION_TYPE, value as u32)); + packet.add(AVP::from_u32(TERMINATION_ACTION_TYPE, value)); } /// Lookup a `termination_action` value-defined integer value from a packet. /// @@ -1100,7 +1100,7 @@ pub fn delete_nas_port_type(packet: &mut Packet) { } /// Add `nas_port_type` value-defined integer value to a packet. pub fn add_nas_port_type(packet: &mut Packet, value: NasPortType) { - packet.add(AVP::from_u32(NAS_PORT_TYPE_TYPE, value as u32)); + packet.add(AVP::from_u32(NAS_PORT_TYPE_TYPE, value)); } /// Lookup a `nas_port_type` value-defined integer value from a packet. /// diff --git a/radius/src/core/rfc2866.rs b/radius/src/core/rfc2866.rs index 73285ef..0afe811 100644 --- a/radius/src/core/rfc2866.rs +++ b/radius/src/core/rfc2866.rs @@ -76,7 +76,7 @@ pub fn delete_acct_status_type(packet: &mut Packet) { } /// Add `acct_status_type` value-defined integer value to a packet. pub fn add_acct_status_type(packet: &mut Packet, value: AcctStatusType) { - packet.add(AVP::from_u32(ACCT_STATUS_TYPE_TYPE, value as u32)); + packet.add(AVP::from_u32(ACCT_STATUS_TYPE_TYPE, value)); } /// Lookup a `acct_status_type` value-defined integer value from a packet. /// @@ -204,7 +204,7 @@ pub fn delete_acct_authentic(packet: &mut Packet) { } /// Add `acct_authentic` value-defined integer value to a packet. pub fn add_acct_authentic(packet: &mut Packet, value: AcctAuthentic) { - packet.add(AVP::from_u32(ACCT_AUTHENTIC_TYPE, value as u32)); + packet.add(AVP::from_u32(ACCT_AUTHENTIC_TYPE, value)); } /// Lookup a `acct_authentic` value-defined integer value from a packet. /// @@ -308,7 +308,7 @@ pub fn delete_acct_terminate_cause(packet: &mut Packet) { } /// Add `acct_terminate_cause` value-defined integer value to a packet. pub fn add_acct_terminate_cause(packet: &mut Packet, value: AcctTerminateCause) { - packet.add(AVP::from_u32(ACCT_TERMINATE_CAUSE_TYPE, value as u32)); + packet.add(AVP::from_u32(ACCT_TERMINATE_CAUSE_TYPE, value)); } /// Lookup a `acct_terminate_cause` value-defined integer value from a packet. /// diff --git a/radius/src/core/rfc2868.rs b/radius/src/core/rfc2868.rs index 9dca809..716e76e 100644 --- a/radius/src/core/rfc2868.rs +++ b/radius/src/core/rfc2868.rs @@ -74,7 +74,7 @@ pub fn delete_tunnel_type(packet: &mut Packet) { } /// Add `tunnel_type` tagged value-defined integer value to a packet. pub fn add_tunnel_type(packet: &mut Packet, tag: Option<&Tag>, value: TunnelType) { - packet.add(AVP::from_tagged_u32(TUNNEL_TYPE_TYPE, tag, value as u32)); + packet.add(AVP::from_tagged_u32(TUNNEL_TYPE_TYPE, tag, value)); } /// Lookup a `tunnel_type` tagged value-defined integer value from a packet. /// @@ -102,11 +102,7 @@ pub fn delete_tunnel_medium_type(packet: &mut Packet) { } /// Add `tunnel_medium_type` tagged value-defined integer value to a packet. pub fn add_tunnel_medium_type(packet: &mut Packet, tag: Option<&Tag>, value: TunnelMediumType) { - packet.add(AVP::from_tagged_u32( - TUNNEL_MEDIUM_TYPE_TYPE, - tag, - value as u32, - )); + packet.add(AVP::from_tagged_u32(TUNNEL_MEDIUM_TYPE_TYPE, tag, value)); } /// Lookup a `tunnel_medium_type` tagged value-defined integer value from a packet. /// diff --git a/radius/src/core/rfc2869.rs b/radius/src/core/rfc2869.rs index c94fd15..980aaa2 100644 --- a/radius/src/core/rfc2869.rs +++ b/radius/src/core/rfc2869.rs @@ -198,7 +198,7 @@ pub fn delete_arap_zone_access(packet: &mut Packet) { } /// Add `arap_zone_access` value-defined integer value to a packet. pub fn add_arap_zone_access(packet: &mut Packet, value: ArapZoneAccess) { - packet.add(AVP::from_u32(ARAP_ZONE_ACCESS_TYPE, value as u32)); + packet.add(AVP::from_u32(ARAP_ZONE_ACCESS_TYPE, value)); } /// Lookup a `arap_zone_access` value-defined integer value from a packet. /// @@ -298,7 +298,7 @@ pub fn delete_prompt(packet: &mut Packet) { } /// Add `prompt` value-defined integer value to a packet. pub fn add_prompt(packet: &mut Packet, value: Prompt) { - packet.add(AVP::from_u32(PROMPT_TYPE, value as u32)); + packet.add(AVP::from_u32(PROMPT_TYPE, value)); } /// Lookup a `prompt` value-defined integer value from a packet. /// diff --git a/radius/src/core/rfc3576.rs b/radius/src/core/rfc3576.rs index ad44d8a..f815265 100644 --- a/radius/src/core/rfc3576.rs +++ b/radius/src/core/rfc3576.rs @@ -51,7 +51,7 @@ pub fn delete_error_cause(packet: &mut Packet) { } /// Add `error_cause` value-defined integer value to a packet. pub fn add_error_cause(packet: &mut Packet, value: ErrorCause) { - packet.add(AVP::from_u32(ERROR_CAUSE_TYPE, value as u32)); + packet.add(AVP::from_u32(ERROR_CAUSE_TYPE, value)); } /// Lookup a `error_cause` value-defined integer value from a packet. /// diff --git a/radius/src/core/rfc4675.rs b/radius/src/core/rfc4675.rs index 87ad060..9551a84 100644 --- a/radius/src/core/rfc4675.rs +++ b/radius/src/core/rfc4675.rs @@ -71,7 +71,7 @@ pub fn delete_ingress_filters(packet: &mut Packet) { } /// Add `ingress_filters` value-defined integer value to a packet. pub fn add_ingress_filters(packet: &mut Packet, value: IngressFilters) { - packet.add(AVP::from_u32(INGRESS_FILTERS_TYPE, value as u32)); + packet.add(AVP::from_u32(INGRESS_FILTERS_TYPE, value)); } /// Lookup a `ingress_filters` value-defined integer value from a packet. /// diff --git a/radius/src/core/rfc5607.rs b/radius/src/core/rfc5607.rs index 68127d5..e3eca06 100644 --- a/radius/src/core/rfc5607.rs +++ b/radius/src/core/rfc5607.rs @@ -51,7 +51,7 @@ pub fn delete_framed_management(packet: &mut Packet) { } /// Add `framed_management` value-defined integer value to a packet. pub fn add_framed_management(packet: &mut Packet, value: FramedManagement) { - packet.add(AVP::from_u32(FRAMED_MANAGEMENT_TYPE, value as u32)); + packet.add(AVP::from_u32(FRAMED_MANAGEMENT_TYPE, value)); } /// Lookup a `framed_management` value-defined integer value from a packet. /// @@ -80,10 +80,7 @@ pub fn add_management_transport_protection( packet: &mut Packet, value: ManagementTransportProtection, ) { - packet.add(AVP::from_u32( - MANAGEMENT_TRANSPORT_PROTECTION_TYPE, - value as u32, - )); + packet.add(AVP::from_u32(MANAGEMENT_TRANSPORT_PROTECTION_TYPE, value)); } /// Lookup a `management_transport_protection` value-defined integer value from a packet. /// diff --git a/radius/src/core/rfc6677.rs b/radius/src/core/rfc6677.rs index d6c8c82..907eec4 100644 --- a/radius/src/core/rfc6677.rs +++ b/radius/src/core/rfc6677.rs @@ -36,7 +36,7 @@ pub fn delete_eap_lower_layer(packet: &mut Packet) { } /// Add `eap_lower_layer` value-defined integer value to a packet. pub fn add_eap_lower_layer(packet: &mut Packet, value: EapLowerLayer) { - packet.add(AVP::from_u32(EAP_LOWER_LAYER_TYPE, value as u32)); + packet.add(AVP::from_u32(EAP_LOWER_LAYER_TYPE, value)); } /// Lookup a `eap_lower_layer` value-defined integer value from a packet. /// diff --git a/radius/src/server.rs b/radius/src/server.rs index 7794eb3..ac891d4 100644 --- a/radius/src/server.rs +++ b/radius/src/server.rs @@ -64,7 +64,7 @@ impl, U: SecretProvider> Server let request_handler_arc = Arc::new(request_handler); let secret_provider_arc = Arc::new(secret_provider); - let address = format!("{}:{}", host, port); + let address = format!("{host}:{port}"); let conn = UdpSocket::bind(address).await?; let conn_arc = Arc::new(conn); @@ -221,7 +221,7 @@ impl, U: SecretProvider> Server { Ok(_) => {} Err(e) => { - println!("{:?}", e); + println!("{e:?}"); } }