Skip to content

Commit

Permalink
Fix clippy lints (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-hiner authored Feb 17, 2023
1 parent b3c4a1b commit a205cfe
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 37 deletions.
4 changes: 2 additions & 2 deletions boringtun-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions boringtun/src/device/dev_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<T> Lock<T> {
impl<T: ?Sized> Lock<T> {
/// Acquire a read lock
pub fn read(&self) -> LockReadGuard<T> {
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
Expand Down Expand Up @@ -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();
Expand 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
}
}
24 changes: 10 additions & 14 deletions boringtun/src/device/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..],
])
Expand Down Expand Up @@ -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]");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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");

Expand All @@ -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),
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion boringtun/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
17 changes: 6 additions & 11 deletions boringtun/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand All @@ -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())
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions boringtun/src/noise/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
8 changes: 4 additions & 4 deletions boringtun/src/noise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ mod tests {

fn create_handshake_response(tun: &mut Tunn, handshake_init: &[u8]) -> Vec<u8> {
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 {
Expand All @@ -643,7 +643,7 @@ mod tests {

fn parse_handshake_resp(tun: &mut Tunn, handshake_resp: &[u8]) -> Vec<u8> {
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 {
Expand All @@ -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));
}

Expand Down Expand Up @@ -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(_)));
}

Expand Down

0 comments on commit a205cfe

Please sign in to comment.