diff --git a/boringtun-cli/src/main.rs b/boringtun-cli/src/main.rs index ef0a2905..026ec29a 100644 --- a/boringtun-cli/src/main.rs +++ b/boringtun-cli/src/main.rs @@ -51,7 +51,7 @@ fn main() { .long("verbosity") .short('v') .env("WG_LOG_LEVEL") - .possible_values(&["error", "info", "debug", "trace"]) + .possible_values(["error", "info", "debug", "trace"]) .help("Log verbosity") .default_value("error"), Arg::new("uapi-fd") @@ -106,7 +106,7 @@ fn main() { let log = matches.value_of("log").unwrap(); let log_file = - File::create(&log).unwrap_or_else(|_| panic!("Could not create log file {}", log)); + File::create(log).unwrap_or_else(|_| panic!("Could not create log file {}", log)); let (non_blocking, guard) = tracing_appender::non_blocking(log_file); diff --git a/boringtun/src/device/dev_lock.rs b/boringtun/src/device/dev_lock.rs index b5bc5967..1a700fab 100644 --- a/boringtun/src/device/dev_lock.rs +++ b/boringtun/src/device/dev_lock.rs @@ -26,7 +26,7 @@ impl Lock { impl Lock { /// Acquire a read lock pub fn read(&self) -> LockReadGuard { - let &(ref lock, ref cvar) = &self.wants_write; + let (ref lock, ref cvar) = &self.wants_write; let mut wants_write = lock.lock(); while *wants_write { // We have a writer and we want to wait for it to go away @@ -90,7 +90,7 @@ impl<'a, T: ?Sized> LockReadGuard<'a, T> { })); // Finally signal other threads - let &(ref lock, ref cvar) = &self.wants_write; + let (ref lock, ref cvar) = &self.wants_write; let mut wants_write = lock.lock(); *wants_write = false; cvar.notify_all(); @@ -103,6 +103,6 @@ impl<'a, T: ?Sized> Deref for LockReadGuard<'a, T> { type Target = T; fn deref(&self) -> &T { - &*self.inner + &self.inner } } diff --git a/boringtun/src/device/integration_tests/mod.rs b/boringtun/src/device/integration_tests/mod.rs index ef8eb7a4..ede23f03 100644 --- a/boringtun/src/device/integration_tests/mod.rs +++ b/boringtun/src/device/integration_tests/mod.rs @@ -70,7 +70,7 @@ mod tests { fn drop(&mut self) { if let Some(name) = &self.container_name { Command::new("docker") - .args(&[ + .args([ "stop", // Run docker &name[5..], ]) @@ -110,11 +110,7 @@ mod tests { // The local endpoint port is the remote listen port let _ = writeln!(conf, "ListenPort = {}", self.endpoint.port()); // HACK: this should consume the key so it can't be reused instead of cloning and serializing - let _ = writeln!( - conf, - "PrivateKey = {}", - base64encode(&self.key.clone().to_bytes()) - ); + let _ = writeln!(conf, "PrivateKey = {}", base64encode(self.key.to_bytes())); // We are the peer let _ = writeln!(conf, "[Peer]"); @@ -147,13 +143,13 @@ mod tests { ) { let peer_config = self.gen_wg_conf(local_key, local_addr, local_port); let peer_config_file = temp_path(); - std::fs::write(&peer_config_file, &peer_config).unwrap(); + std::fs::write(&peer_config_file, peer_config).unwrap(); let nginx_config = self.gen_nginx_conf(); let nginx_config_file = format!("{}.ngx", peer_config_file); - std::fs::write(&nginx_config_file, &nginx_config).unwrap(); + std::fs::write(&nginx_config_file, nginx_config).unwrap(); Command::new("docker") - .args(&[ + .args([ "run", // Run docker "-d", // In detached mode "--cap-add=NET_ADMIN", // Grant permissions to open a tunnel @@ -352,7 +348,7 @@ mod tests { /// Starts the tunnel fn start(&mut self) { Command::new("ip") - .args(&[ + .args([ "address", "add", &self.addr_v4.to_string(), @@ -363,7 +359,7 @@ mod tests { .expect("failed to assign ip to tunnel"); Command::new("ip") - .args(&[ + .args([ "address", "add", &self.addr_v6.to_string(), @@ -375,7 +371,7 @@ mod tests { // Start the tunnel Command::new("ip") - .args(&["link", "set", "mtu", "1400", "up", "dev", &self.name]) + .args(["link", "set", "mtu", "1400", "up", "dev", &self.name]) .status() .expect("failed to start the tunnel"); @@ -385,7 +381,7 @@ mod tests { for p in &self.peers { for r in &p.allowed_ips { Command::new("ip") - .args(&[ + .args([ "route", "add", &format!("{}/{}", r.ip, r.cidr), @@ -462,7 +458,7 @@ mod tests { let mut path = String::from("/tmp/"); let mut buf = [0u8; 32]; SystemRandom::new().fill(&mut buf[..]).unwrap(); - path.push_str(&encode(&buf)); + path.push_str(&encode(buf)); path } diff --git a/boringtun/src/device/mod.rs b/boringtun/src/device/mod.rs index d8c13e98..b73fa8c5 100644 --- a/boringtun/src/device/mod.rs +++ b/boringtun/src/device/mod.rs @@ -186,7 +186,7 @@ impl DeviceHandle { pub fn clean(&mut self) { for path in &self.device.read().cleanup_paths { // attempt to remove any file we created in the work dir - let _ = std::fs::remove_file(&path); + let _ = std::fs::remove_file(path); } } diff --git a/boringtun/src/ffi/mod.rs b/boringtun/src/ffi/mod.rs index f04987b8..4c77af9e 100644 --- a/boringtun/src/ffi/mod.rs +++ b/boringtun/src/ffi/mod.rs @@ -118,7 +118,7 @@ pub extern "C" fn x25519_public_key(private_key: x25519_key) -> x25519_key { /// The memory has to be freed by calling `x25519_key_to_str_free` #[no_mangle] pub extern "C" fn x25519_key_to_base64(key: x25519_key) -> *const c_char { - let encoded_key = encode(&key.key); + let encoded_key = encode(key.key); CString::into_raw(CString::new(encoded_key).unwrap()) } @@ -127,7 +127,7 @@ pub extern "C" fn x25519_key_to_base64(key: x25519_key) -> *const c_char { /// The memory has to be freed by calling `x25519_key_to_str_free` #[no_mangle] pub extern "C" fn x25519_key_to_hex(key: x25519_key) -> *const c_char { - let encoded_key = encode_hex(&key.key); + let encoded_key = encode_hex(key.key); CString::into_raw(CString::new(encoded_key).unwrap()) } @@ -147,7 +147,7 @@ pub unsafe extern "C" fn check_base64_encoded_x25519_key(key: *const c_char) -> Ok(string) => string, }; - if let Ok(key) = decode(&utf8_key) { + if let Ok(key) = decode(utf8_key) { let len = key.len(); let mut zero = 0u8; for b in key { @@ -223,23 +223,18 @@ pub unsafe extern "C" fn set_logging_function( // disable terminal escape codes .with_ansi(false); - if fmt() + fmt() .event_format(format) .with_writer(std::sync::Mutex::new(writer)) .with_max_level(tracing::Level::TRACE) .with_ansi(false) .try_init() .is_ok() - { - return true; - } - - return false; }); if let Ok(value) = result { - return value; + value } else { - return false; + false } } diff --git a/boringtun/src/noise/handshake.rs b/boringtun/src/noise/handshake.rs index 4a76211f..1dd096c6 100644 --- a/boringtun/src/noise/handshake.rs +++ b/boringtun/src/noise/handshake.rs @@ -136,8 +136,8 @@ fn aead_chacha20_open( } #[inline] -fn aead_chacha20_open_inner<'in_out>( - buffer: &'in_out mut [u8], +fn aead_chacha20_open_inner( + buffer: &mut [u8], key: &[u8], nonce: [u8; 12], data: &[u8], diff --git a/boringtun/src/noise/mod.rs b/boringtun/src/noise/mod.rs index 592923b4..60c814fb 100644 --- a/boringtun/src/noise/mod.rs +++ b/boringtun/src/noise/mod.rs @@ -629,7 +629,7 @@ mod tests { fn create_handshake_response(tun: &mut Tunn, handshake_init: &[u8]) -> Vec { let mut dst = vec![0u8; 2048]; - let handshake_resp = tun.decapsulate(None, &handshake_init, &mut dst); + let handshake_resp = tun.decapsulate(None, handshake_init, &mut dst); assert!(matches!(handshake_resp, TunnResult::WriteToNetwork(_))); let handshake_resp = if let TunnResult::WriteToNetwork(sent) = handshake_resp { @@ -643,7 +643,7 @@ mod tests { fn parse_handshake_resp(tun: &mut Tunn, handshake_resp: &[u8]) -> Vec { let mut dst = vec![0u8; 2048]; - let keepalive = tun.decapsulate(None, &handshake_resp, &mut dst); + let keepalive = tun.decapsulate(None, handshake_resp, &mut dst); assert!(matches!(keepalive, TunnResult::WriteToNetwork(_))); let keepalive = if let TunnResult::WriteToNetwork(sent) = keepalive { @@ -657,7 +657,7 @@ mod tests { fn parse_keepalive(tun: &mut Tunn, keepalive: &[u8]) { let mut dst = vec![0u8; 2048]; - let keepalive = tun.decapsulate(None, &keepalive, &mut dst); + let keepalive = tun.decapsulate(None, keepalive, &mut dst); assert!(matches!(keepalive, TunnResult::Done)); } @@ -690,7 +690,7 @@ mod tests { } else { unreachable!(); }; - let packet = Tunn::parse_incoming_packet(&packet_data).unwrap(); + let packet = Tunn::parse_incoming_packet(packet_data).unwrap(); assert!(matches!(packet, Packet::HandshakeInit(_))); }