Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
Especially https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string was a bit
more involved, review requested.
  • Loading branch information
strohel committed Aug 1, 2022
1 parent 986a47f commit 144c2f6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
4 changes: 2 additions & 2 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ fn delete_cidr(
let cidr_id = prompts::delete_cidr(&cidrs, &peers, &sub_opts)?;

println!("Deleting CIDR...");
let _ = api.http("DELETE", &*format!("/admin/cidrs/{}", cidr_id))?;
api.http("DELETE", &*format!("/admin/cidrs/{}", cidr_id))?;

println!("CIDR deleted.");

Expand Down Expand Up @@ -801,7 +801,7 @@ fn rename_peer(
.next()
.ok_or_else(|| anyhow!("Peer not found."))?;

let _ = api.http_form("PUT", &format!("/admin/peers/{}", id), peer_request)?;
api.http_form("PUT", &format!("/admin/peers/{}", id), peer_request)?;
log::info!("Peer renamed.");
} else {
log::info!("exited without renaming peer.");
Expand Down
4 changes: 2 additions & 2 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ fn rename_peer(
.into_iter()
.find(|p| p.name == old_name)
.ok_or_else(|| anyhow!("Peer not found."))?;
let _peer = db_peer.update(&conn, peer_request)?;
db_peer.update(&conn, peer_request)?;
} else {
println!("exited without creating peer.");
}
Expand Down Expand Up @@ -408,7 +408,7 @@ fn delete_cidr(
let cidr_id = prompts::delete_cidr(&cidrs, &peers, &args)?;

println!("Deleting CIDR...");
let _ = DatabaseCidr::delete(&conn, cidr_id)?;
DatabaseCidr::delete(&conn, cidr_id)?;

println!("CIDR deleted.");

Expand Down
4 changes: 2 additions & 2 deletions wireguard-control/src/backends/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ macro_rules! get_nla_value {
};
}

impl<'a> TryFrom<WgAllowedIp> for AllowedIp {
impl TryFrom<WgAllowedIp> for AllowedIp {
type Error = io::Error;

fn try_from(attrs: WgAllowedIp) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl PeerConfigBuilder {
}
}

impl<'a> TryFrom<WgPeer> for PeerInfo {
impl TryFrom<WgPeer> for PeerInfo {
type Error = io::Error;

fn try_from(attrs: WgPeer) -> Result<Self, Self::Error> {
Expand Down
45 changes: 25 additions & 20 deletions wireguard-control/src/backends/userspace.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{Backend, Device, DeviceUpdate, InterfaceName, PeerConfig, PeerInfo, PeerStats};

use crate::Key;
use crate::{Backend, Device, DeviceUpdate, InterfaceName, Key, PeerConfig, PeerInfo, PeerStats};

use std::{
fmt::Write as _,
fs,
io::{self, prelude::*, BufReader},
os::unix::net::UnixStream,
Expand Down Expand Up @@ -311,55 +310,61 @@ pub fn apply(builder: &DeviceUpdate, iface: &InterfaceName) -> io::Result<()> {
let mut request = String::from("set=1\n");

if let Some(ref k) = builder.private_key {
request.push_str(&format!("private_key={}\n", hex::encode(k.as_bytes())));
writeln!(request, "private_key={}", hex::encode(k.as_bytes())).ok();
}

if let Some(f) = builder.fwmark {
request.push_str(&format!("fwmark={}\n", f));
writeln!(request, "fwmark={}", f).ok();
}

if let Some(f) = builder.listen_port {
request.push_str(&format!("listen_port={}\n", f));
writeln!(request, "listen_port={}", f).ok();
}

if builder.replace_peers {
request.push_str("replace_peers=true\n");
writeln!(request, "replace_peers=true").ok();
}

for peer in &builder.peers {
request.push_str(&format!(
"public_key={}\n",
writeln!(
request,
"public_key={}",
hex::encode(peer.public_key.as_bytes())
));
)
.ok();

if peer.replace_allowed_ips {
request.push_str("replace_allowed_ips=true\n");
writeln!(request, "replace_allowed_ips=true").ok();
}

if peer.remove_me {
request.push_str("remove=true\n");
writeln!(request, "remove=true").ok();
}

if let Some(ref k) = peer.preshared_key {
request.push_str(&format!("preshared_key={}\n", hex::encode(k.as_bytes())));
writeln!(request, "preshared_key={}", hex::encode(k.as_bytes())).ok();
}

if let Some(endpoint) = peer.endpoint {
request.push_str(&format!("endpoint={}\n", endpoint));
writeln!(request, "endpoint={}", endpoint).ok();
}

if let Some(keepalive_interval) = peer.persistent_keepalive_interval {
request.push_str(&format!(
"persistent_keepalive_interval={}\n",
writeln!(
request,
"persistent_keepalive_interval={}",
keepalive_interval
));
)
.ok();
}

for allowed_ip in &peer.allowed_ips {
request.push_str(&format!(
"allowed_ip={}/{}\n",
writeln!(
request,
"allowed_ip={}/{}",
allowed_ip.address, allowed_ip.cidr
));
)
.ok();
}
}

Expand Down

0 comments on commit 144c2f6

Please sign in to comment.