aboutsummaryrefslogtreecommitdiffstats
path: root/src/wireguard/handshake
diff options
context:
space:
mode:
authorQuang Luong <quangio@outlook.com>2020-09-18 11:20:06 +0700
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2020-10-08 10:19:51 +0200
commit9b53a9d1a61115a328ca43955153d09cc2e969ef (patch)
treeb84d83a431dfdc5777e61d40c60c7b0de088f8fd /src/wireguard/handshake
parentAdded MIT license (diff)
downloadwireguard-rs-9b53a9d1a61115a328ca43955153d09cc2e969ef.tar.xz
wireguard-rs-9b53a9d1a61115a328ca43955153d09cc2e969ef.zip
Fix some clippy warnings
Signed-off-by: Quang Luong <quangio@outlook.com>
Diffstat (limited to 'src/wireguard/handshake')
-rw-r--r--src/wireguard/handshake/device.rs18
-rw-r--r--src/wireguard/handshake/noise.rs2
-rw-r--r--src/wireguard/handshake/peer.rs34
-rw-r--r--src/wireguard/handshake/ratelimiter.rs2
-rw-r--r--src/wireguard/handshake/timestamp.rs2
5 files changed, 20 insertions, 38 deletions
diff --git a/src/wireguard/handshake/device.rs b/src/wireguard/handshake/device.rs
index 5e69921..d71f351 100644
--- a/src/wireguard/handshake/device.rs
+++ b/src/wireguard/handshake/device.rs
@@ -118,7 +118,9 @@ impl<O> Device<O> {
} else {
peer.ss.clear();
}
- peer.reset_state().map(|id| ids.push(id));
+ if let Some(id) = peer.reset_state() {
+ ids.push(id)
+ }
}
(ids, same)
@@ -212,7 +214,7 @@ impl<O> Device<O> {
// remove the peer
self.pk_map
.remove(pk.as_bytes())
- .ok_or(ConfigError::new("Public key not in device"))?;
+ .ok_or_else(|| ConfigError::new("Public key not in device"))?;
// remove every id entry for the peer in the public key map
// O(n) operations, however it is rare: only when removing peers.
@@ -389,9 +391,6 @@ impl<O> Device<O> {
// address validation & DoS mitigation
if let Some(src) = src {
- // obtain ref to socket addr
- let src = src.into();
-
// check mac2 field
if !keyst.macs.check_mac2(msg.noise.as_bytes(), &src, &msg.macs) {
let mut reply = Default::default();
@@ -471,12 +470,9 @@ impl<O> Device<O> {
}
// write lock the shard and insert
- match self.id_map.entry(id) {
- Entry::Vacant(entry) => {
- entry.insert(*pk.as_bytes());
- return id;
- }
- _ => (),
+ if let Entry::Vacant(entry) = self.id_map.entry(id) {
+ entry.insert(*pk.as_bytes());
+ return id;
};
}
}
diff --git a/src/wireguard/handshake/noise.rs b/src/wireguard/handshake/noise.rs
index 4141cb9..475b159 100644
--- a/src/wireguard/handshake/noise.rs
+++ b/src/wireguard/handshake/noise.rs
@@ -11,8 +11,6 @@ use hmac::Hmac;
use aead::{Aead, NewAead, Payload};
use chacha20poly1305::ChaCha20Poly1305;
-use log;
-
use rand::prelude::{CryptoRng, RngCore};
use generic_array::typenum::*;
diff --git a/src/wireguard/handshake/peer.rs b/src/wireguard/handshake/peer.rs
index 1636e62..f847725 100644
--- a/src/wireguard/handshake/peer.rs
+++ b/src/wireguard/handshake/peer.rs
@@ -50,13 +50,10 @@ pub enum State {
impl Drop for State {
fn drop(&mut self) {
- match self {
- State::InitiationSent { hs, ck, .. } => {
- // eph_sk already cleared by dalek-x25519
- hs.clear();
- ck.clear();
- }
- _ => (),
+ if let State::InitiationSent { hs, ck, .. } = self {
+ // eph_sk already cleared by dalek-x25519
+ hs.clear();
+ ck.clear();
}
}
}
@@ -97,29 +94,22 @@ impl<O> Peer<O> {
let mut last_initiation_consumption = self.last_initiation_consumption.lock();
// check replay attack
- match *timestamp {
- Some(timestamp_old) => {
- if !timestamp::compare(&timestamp_old, &timestamp_new) {
- return Err(HandshakeError::OldTimestamp);
- }
+ if let Some(timestamp_old) = *timestamp {
+ if !timestamp::compare(&timestamp_old, &timestamp_new) {
+ return Err(HandshakeError::OldTimestamp);
}
- _ => (),
};
// check flood attack
- match *last_initiation_consumption {
- Some(last) => {
- if last.elapsed() < TIME_BETWEEN_INITIATIONS {
- return Err(HandshakeError::InitiationFlood);
- }
+ if let Some(last) = *last_initiation_consumption {
+ if last.elapsed() < TIME_BETWEEN_INITIATIONS {
+ return Err(HandshakeError::InitiationFlood);
}
- _ => (),
}
// reset state
- match *state {
- State::InitiationSent { local, .. } => device.release(local),
- _ => (),
+ if let State::InitiationSent { local, .. } = *state {
+ device.release(local)
}
// update replay & flood protection
diff --git a/src/wireguard/handshake/ratelimiter.rs b/src/wireguard/handshake/ratelimiter.rs
index 89109e9..f6210fc 100644
--- a/src/wireguard/handshake/ratelimiter.rs
+++ b/src/wireguard/handshake/ratelimiter.rs
@@ -5,8 +5,6 @@ use std::sync::{Arc, Condvar, Mutex};
use std::thread;
use std::time::{Duration, Instant};
-use spin;
-
const PACKETS_PER_SECOND: u64 = 20;
const PACKETS_BURSTABLE: u64 = 5;
const PACKET_COST: u64 = 1_000_000_000 / PACKETS_PER_SECOND;
diff --git a/src/wireguard/handshake/timestamp.rs b/src/wireguard/handshake/timestamp.rs
index b5bd9f0..485bb8d 100644
--- a/src/wireguard/handshake/timestamp.rs
+++ b/src/wireguard/handshake/timestamp.rs
@@ -28,5 +28,5 @@ pub fn compare(old: &TAI64N, new: &TAI64N) -> bool {
return true;
}
}
- return false;
+ false
}