diff --git a/src/configuration/uapi/mod.rs b/src/configuration/uapi/mod.rs index 63a8d5f7..cf1bb30e 100644 --- a/src/configuration/uapi/mod.rs +++ b/src/configuration/uapi/mod.rs @@ -40,7 +40,7 @@ pub fn handle(stream: &mut S, config: &C) { (Some(key), Some(value)) => Ok((key, value)), _ => Err(ConfigError::LineTooLong), } - }; + } // read operation line match readline(stream)?.as_str() { @@ -53,7 +53,7 @@ pub fn handle(stream: &mut S, config: &C) { let mut parser = LineParser::new(config); loop { let ln = readline(stream)?; - if ln == "" { + if ln.is_empty() { break; } let (k, v) = keypair(ln.as_str())?; diff --git a/src/configuration/uapi/set.rs b/src/configuration/uapi/set.rs index 665f090b..bb4ddbef 100644 --- a/src/configuration/uapi/set.rs +++ b/src/configuration/uapi/set.rs @@ -101,7 +101,7 @@ impl<'a, C: Configuration> LineParser<'a, C> { }; None - }; + } // parse line and update parser state match self.state { @@ -167,7 +167,7 @@ impl<'a, C: Configuration> LineParser<'a, C> { ParserState::Peer(ref mut peer) => match key { // opt: new peer "public_key" => { - flush_peer(self.config, &peer); + flush_peer(self.config, peer); self.state = Self::new_peer(value)?; Ok(()) } @@ -247,7 +247,7 @@ impl<'a, C: Configuration> LineParser<'a, C> { // flush (used at end of transcipt) "" => { log::trace!("UAPI, Set, processes end of transaction"); - flush_peer(self.config, &peer); + flush_peer(self.config, peer); Ok(()) } diff --git a/src/platform/dummy/endpoint.rs b/src/platform/dummy/endpoint.rs index f5fc32c4..05d7d82b 100644 --- a/src/platform/dummy/endpoint.rs +++ b/src/platform/dummy/endpoint.rs @@ -10,7 +10,7 @@ impl Endpoint for UnitEndpoint { UnitEndpoint {} } - fn into_address(&self) -> SocketAddr { + fn to_address(&self) -> SocketAddr { "127.0.0.1:8080".parse().unwrap() } diff --git a/src/platform/endpoint.rs b/src/platform/endpoint.rs index 4702aab3..ef4da9a5 100644 --- a/src/platform/endpoint.rs +++ b/src/platform/endpoint.rs @@ -2,6 +2,6 @@ use std::net::SocketAddr; pub trait Endpoint: Send + 'static { fn from_address(addr: SocketAddr) -> Self; - fn into_address(&self) -> SocketAddr; + fn to_address(&self) -> SocketAddr; fn clear_src(&mut self); } diff --git a/src/platform/linux/udp.rs b/src/platform/linux/udp.rs index b62d5bfa..28ece0db 100644 --- a/src/platform/linux/udp.rs +++ b/src/platform/linux/udp.rs @@ -165,7 +165,7 @@ impl Endpoint for LinuxEndpoint { } } - fn into_address(&self) -> SocketAddr { + fn to_address(&self) -> SocketAddr { match self { LinuxEndpoint::V4(EndpointV4 { ref dst, .. }) => { SocketAddr::V4(SocketAddrV4::new( diff --git a/src/platform/udp.rs b/src/platform/udp.rs index 0b9c823c..0af2d411 100644 --- a/src/platform/udp.rs +++ b/src/platform/udp.rs @@ -13,6 +13,7 @@ pub trait Writer: Send + Sync + 'static { fn write(&self, buf: &[u8], dst: &mut E) -> Result<(), Self::Error>; } +#[allow(clippy::upper_case_acronyms)] pub trait UDP: Send + Sync + 'static { type Error: Error; type Endpoint: Endpoint; diff --git a/src/wireguard/handshake/messages.rs b/src/wireguard/handshake/messages.rs index 29d80afc..554799dd 100644 --- a/src/wireguard/handshake/messages.rs +++ b/src/wireguard/handshake/messages.rs @@ -36,14 +36,14 @@ pub const MAX_HANDSHAKE_MSG_SIZE: usize = max( /* Handshake messsages */ #[repr(packed)] -#[derive(Copy, Clone, FromBytes, AsBytes)] +#[derive(Copy, Clone, FromBytes, AsBytes, Default)] pub struct Response { pub noise: NoiseResponse, // inner message covered by macs pub macs: MacsFooter, } #[repr(packed)] -#[derive(Copy, Clone, FromBytes, AsBytes)] +#[derive(Copy, Clone, FromBytes, AsBytes, Default)] pub struct Initiation { pub noise: NoiseInitiation, // inner message covered by macs pub macs: MacsFooter, @@ -130,24 +130,6 @@ impl CookieReply { /* Default values */ -impl Default for Response { - fn default() -> Self { - Self { - noise: Default::default(), - macs: Default::default(), - } - } -} - -impl Default for Initiation { - fn default() -> Self { - Self { - noise: Default::default(), - macs: Default::default(), - } - } -} - impl Default for CookieReply { fn default() -> Self { Self { diff --git a/src/wireguard/handshake/noise.rs b/src/wireguard/handshake/noise.rs index 92c8c5f4..da2b66c1 100644 --- a/src/wireguard/handshake/noise.rs +++ b/src/wireguard/handshake/noise.rs @@ -271,7 +271,7 @@ pub(super) fn create_initiation( // (C, k) := Kdf2(C, DH(E_priv, S_pub)) - let (ck, key) = KDF2!(&ck, shared_secret(&eph_sk, &pk)?.as_bytes()); + let (ck, key) = KDF2!(&ck, shared_secret(&eph_sk, pk)?.as_bytes()); // msg.static := Aead(k, 0, S_pub, H) @@ -444,7 +444,7 @@ pub(super) fn create_response( // C := Kdf1(C, DH(E_priv, S_pub)) - let ck = KDF1!(&ck, shared_secret(&eph_sk, &pk)?.as_bytes()); + let ck = KDF1!(&ck, shared_secret(&eph_sk, pk)?.as_bytes()); // (C, tau, k) := Kdf3(C, Q) diff --git a/src/wireguard/handshake/peer.rs b/src/wireguard/handshake/peer.rs index f8477254..964006c1 100644 --- a/src/wireguard/handshake/peer.rs +++ b/src/wireguard/handshake/peer.rs @@ -95,7 +95,7 @@ impl Peer { // check replay attack if let Some(timestamp_old) = *timestamp { - if !timestamp::compare(×tamp_old, ×tamp_new) { + if !timestamp::compare(×tamp_old, timestamp_new) { return Err(HandshakeError::OldTimestamp); } }; diff --git a/src/wireguard/router/device.rs b/src/wireguard/router/device.rs index eeae621e..f7945dd5 100644 --- a/src/wireguard/router/device.rs +++ b/src/wireguard/router/device.rs @@ -209,7 +209,7 @@ impl> DeviceHandle< /// /// # Returns pub fn recv(&self, src: E, msg: Vec) -> Result<(), RouterError> { - log::trace!("receive, src: {}", src.into_address()); + log::trace!("receive, src: {}", src.to_address()); // parse / cast let (header, _) = match LayoutVerified::new_from_prefix(&msg[..]) { diff --git a/src/wireguard/router/peer.rs b/src/wireguard/router/peer.rs index 0803b138..8ba6f021 100644 --- a/src/wireguard/router/peer.rs +++ b/src/wireguard/router/peer.rs @@ -324,12 +324,12 @@ impl> Peer> PeerHandle Option { log::trace!("peer.get_endpoint"); - self.peer.endpoint.lock().as_ref().map(|e| e.into_address()) + self.peer.endpoint.lock().as_ref().map(|e| e.to_address()) } /// Zero all key-material related to the peer @@ -440,7 +440,7 @@ impl> PeerHandle> ParallelJob * since this can cause dropping of packets (leaving the window) due to scheduling. */ fn parallel_work(&self) { - debug_assert_eq!( - self.is_ready(), - false, + debug_assert!( + !self.is_ready(), "doing parallel work on completed job" ); log::trace!("processing parallel receive job"); @@ -109,7 +108,7 @@ impl> ParallelJob } // check crypto-key router - packet.len() == SIZE_TAG || peer.device.table.check_route(&peer, &packet) + packet.len() == SIZE_TAG || peer.device.table.check_route(peer, packet) })(); // remove message in case of failure: @@ -132,9 +131,8 @@ impl> SequentialJob } fn sequential_work(self) { - debug_assert_eq!( + debug_assert!( self.is_ready(), - true, "doing sequential work on an incomplete job" ); log::trace!("processing sequential receive job"); diff --git a/src/wireguard/router/send.rs b/src/wireguard/router/send.rs index 7e142095..34520a8b 100644 --- a/src/wireguard/router/send.rs +++ b/src/wireguard/router/send.rs @@ -57,9 +57,8 @@ impl> ParallelJob } fn parallel_work(&self) { - debug_assert_eq!( - self.is_ready(), - false, + debug_assert!( + !self.is_ready(), "doing parallel work on completed job" ); log::trace!("processing parallel send job"); @@ -117,9 +116,8 @@ impl> SequentialJob } fn sequential_work(self) { - debug_assert_eq!( + debug_assert!( self.is_ready(), - true, "doing sequential work on an incomplete job" ); diff --git a/src/wireguard/workers.rs b/src/wireguard/workers.rs index 27acf2f5..ad4cc554 100644 --- a/src/wireguard/workers.rs +++ b/src/wireguard/workers.rs @@ -184,7 +184,7 @@ pub fn handshake_worker( &mut OsRng, &msg[..], if under_load { - Some(src.into_address()) + Some(src.to_address()) } else { None },