Skip to content

Commit

Permalink
cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
a-moreira committed Jul 6, 2023
1 parent 528dac8 commit 7dc9c43
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 29 deletions.
10 changes: 4 additions & 6 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
mod util;

use std::{
fs,
ops::Deref,
time::{Duration, Instant},
};
Expand All @@ -12,13 +11,12 @@ use clap::{Args, CommandFactory, Parser, Subcommand};
use cli_clipboard::{ClipboardContext, ClipboardProvider};
use color_eyre::{eyre, eyre::Context};
use console::{style, Term};
use dialoguer::{Completion, Input};
use dialoguer::{Input};
use futures::{future::Either, Future, FutureExt};
use indicatif::{MultiProgress, ProgressBar};
use magic_wormhole::PgpWordList;
use magic_wormhole::{forwarding, transfer, transit, Wormhole};
use std::{
collections::HashMap,
io::Write,
path::{Path, PathBuf},
};
Expand Down Expand Up @@ -577,7 +575,7 @@ async fn main() -> eyre::Result<()> {
out,
);

std::io::stdout().write_all(&out.as_bytes())?;
std::io::stdout().write_all(out.as_bytes())?;
},
shell => {
let mut out = std::io::stdout();
Expand Down Expand Up @@ -1023,15 +1021,15 @@ async fn receive(
.truncate(true)
.open(&file_path)
.await?;
Ok(req
req
.accept(
&transit::log_transit_connection,
on_progress,
&mut file,
ctrl_c(),
)
.await
.context("Receive process failed")?)
.context("Receive process failed")
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion cli/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn ask_user(message: impl std::fmt::Display, default_answer: bool) ->
let mut answer = String::new();
stdin.read_line(&mut answer).await.unwrap();

match &*answer.to_lowercase().trim() {
match answer.to_lowercase().trim() {
"y" | "yes" => break true,
"n" | "no" => break false,
"" => break default_answer,
Expand Down
8 changes: 4 additions & 4 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,9 @@ impl Nameplate {
}
}

impl Into<String> for Nameplate {
fn into(self) -> String {
self.0
impl From<Nameplate> for String {
fn from(val: Nameplate) -> Self {
val.0
}
}

Expand All @@ -545,6 +545,6 @@ impl Code {
}

pub fn nameplate(&self) -> Nameplate {
Nameplate::new(self.0.splitn(2, '-').next().unwrap())
Nameplate::new(self.0.split('-').next().unwrap())
}
}
6 changes: 3 additions & 3 deletions src/core/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Key<WormholeKey> {
*/
#[cfg(feature = "transit")]
pub fn derive_transit_key(&self, appid: &AppID) -> Key<crate::transit::TransitKey> {
let transit_purpose = format!("{}/transit-key", &*appid);
let transit_purpose = format!("{}/transit-key", appid);

let derived_key = self.derive_subkey_from_purpose(&transit_purpose);
trace!(
Expand All @@ -68,15 +68,15 @@ impl<P: KeyPurpose> Key<P> {
}

pub fn to_hex(&self) -> String {
hex::encode(&**self)
hex::encode(**self)
}

/**
* Derive a new sub-key from this one
*/
pub fn derive_subkey_from_purpose<NewP: KeyPurpose>(&self, purpose: &str) -> Key<NewP> {
Key(
Box::new(derive_key(&*self, purpose.as_bytes())),
Box::new(derive_key(self, purpose.as_bytes())),
std::marker::PhantomData,
)
}
Expand Down
16 changes: 8 additions & 8 deletions src/core/wordlist.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rand::{rngs::OsRng, seq::SliceRandom};
use serde_json::{self, Value};
use std::fmt;


use dialoguer::Completion;
use std::collections::HashMap;
Expand All @@ -14,8 +14,8 @@ pub struct PgpWordList {
impl PgpWordList {
pub fn choose_words(&self) -> String {
let mut rng = OsRng;
let components: Vec<String>;
components = self

let components: Vec<String> = self
.words
.iter()
.cycle()
Expand Down Expand Up @@ -62,23 +62,23 @@ impl Completion for PgpWordList {
let mut suffix: String = input.to_owned();
if word.starts_with(last_partial_word.unwrap()) {
if lp == 0 {
suffix.push_str(&word);
suffix.push_str(word);
} else {
let p = input.len() - lp;
suffix.truncate(p as usize);
suffix.push_str(&word);
suffix.truncate(p);
suffix.push_str(word);
}

if count_dashes + 1 < self.num_words {
suffix.push_str("-");
suffix.push('-');
}

completions.push(suffix);
}
}
if completions.len() == 1 {
Some(completions.first().unwrap().clone())
} else if completions.len() == 0 {
} else if completions.is_empty() {
None
} else {
// TODO: show vector of suggestions somehow
Expand Down
8 changes: 4 additions & 4 deletions src/transit/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl TransitCryptoInit for NoiseInit {
builder.set_is_initiator(true);
builder.build_handshake_state()
};
handshake.push_psk(&*self.key);
handshake.push_psk(&self.key);

// → psk, e
write_transit_message(socket, &handshake.write_message_vec(&[])?).await?;
Expand All @@ -307,7 +307,7 @@ impl TransitCryptoInit for NoiseInit {
// ← ""
let peer_confirmation_message = rx.decrypt_vec(&read_transit_message(socket).await?)?;
ensure!(
peer_confirmation_message.len() == 0,
peer_confirmation_message.is_empty(),
TransitHandshakeError::HandshakeFailed
);

Expand Down Expand Up @@ -354,7 +354,7 @@ impl TransitCryptoInit for NoiseInit {
builder.set_is_initiator(false);
builder.build_handshake_state()
};
handshake.push_psk(&*self.key);
handshake.push_psk(&self.key);

// ← psk, e
handshake.read_message(&read_transit_message(socket).await?, &mut [])?;
Expand All @@ -372,7 +372,7 @@ impl TransitCryptoInit for NoiseInit {
// ← ""
let peer_confirmation_message = rx.decrypt_vec(&read_transit_message(socket).await?)?;
ensure!(
peer_confirmation_message.len() == 0,
peer_confirmation_message.is_empty(),
TransitHandshakeError::HandshakeFailed
);

Expand Down
4 changes: 2 additions & 2 deletions src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ impl std::str::FromStr for WormholeTransferUri {
impl From<&WormholeTransferUri> for url::Url {
fn from(val: &WormholeTransferUri) -> Self {
let mut url = url::Url::parse("wormhole-transfer:").unwrap();
url.set_path(&*val.code);
url.set_path(&val.code);
/* Only do this if there are any query parameteres at all, otherwise the URL will have an ugly trailing '?'. */
if val.rendezvous_server.is_some() || val.is_leader {
let mut query = url.query_pairs_mut();
query.clear();
if let Some(rendezvous_server) = val.rendezvous_server.as_ref() {
query.append_pair("rendezvous", &rendezvous_server.to_string());
query.append_pair("rendezvous", rendezvous_server.as_ref());
}
if val.is_leader {
query.append_pair("role", "leader");
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct DisplayBytes<'a>(pub &'a [u8]);

impl std::fmt::Display for DisplayBytes<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let hex_decode = hex::decode(&self.0);
let hex_decode = hex::decode(self.0);
let (string, hex_param) = match hex_decode.as_ref().map(Vec::as_slice) {
Ok(decoded_hex) => (decoded_hex, "hex-encoded "),
Err(_) => (self.0, ""),
Expand Down

0 comments on commit 7dc9c43

Please sign in to comment.