Skip to content

Commit 69eefaf

Browse files
authored
Fixed bunch of clippy warnings (#427)
1 parent 7d69419 commit 69eefaf

File tree

43 files changed

+102
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+102
-152
lines changed

clients/client-core/src/client/cover_traffic_stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl LoopCoverTrafficStream<OsRng> {
171171
self.average_cover_message_sending_delay,
172172
));
173173

174-
while let Some(_) = self.next().await {
174+
while self.next().await.is_some() {
175175
self.on_new_message().await;
176176
}
177177
}

clients/client-core/src/client/real_messages_control/acknowledgement_control/input_message_listener.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ where
152152
pending_acks.push(PendingAcknowledgement::new(
153153
message_chunk,
154154
prepared_fragment.total_delay,
155-
recipient.clone(),
155+
recipient,
156156
));
157157
}
158158

clients/client-core/src/client/real_messages_control/acknowledgement_control/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ where
194194

195195
let message_preparer = MessagePreparer::new(
196196
rng,
197-
ack_recipient.clone(),
197+
ack_recipient,
198198
config.average_packet_delay,
199199
config.average_ack_delay,
200200
config.packet_mode,
@@ -211,7 +211,7 @@ where
211211
// will listen for any new messages from the client
212212
let input_message_listener = InputMessageListener::new(
213213
Arc::clone(&ack_key),
214-
ack_recipient.clone(),
214+
ack_recipient,
215215
connectors.input_receiver,
216216
message_preparer.clone(),
217217
action_sender.clone(),

clients/client-core/src/client/real_messages_control/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl RealMessagesController<OsRng> {
143143
rng,
144144
topology_access.clone(),
145145
Arc::clone(&config.ack_key),
146-
config.self_recipient.clone(),
146+
config.self_recipient,
147147
reply_key_storage,
148148
ack_controller_connectors,
149149
);

clients/native/src/client/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl NymClient {
8989
pub fn as_mix_recipient(&self) -> Recipient {
9090
Recipient::new(
9191
*self.key_manager.identity_keypair().public_key(),
92-
self.key_manager.encryption_keypair().public_key().clone(),
92+
*self.key_manager.encryption_keypair().public_key(),
9393
// TODO: below only works under assumption that gateway address == gateway id
9494
// (which currently is true)
9595
NodeIdentity::from_base58_string(self.config.get_base().get_gateway_id()).unwrap(),

clients/native/src/websocket/handler.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Clone for Handler {
5757
Handler {
5858
msg_input: self.msg_input.clone(),
5959
buffer_requester: self.buffer_requester.clone(),
60-
self_full_address: self.self_full_address.clone(),
60+
self_full_address: self.self_full_address,
6161
socket: None,
6262
received_response_type: Default::default(),
6363
}
@@ -112,7 +112,7 @@ impl Handler {
112112
}
113113

114114
fn handle_self_address(&self) -> ServerResponse {
115-
ServerResponse::SelfAddress(self.self_full_address.clone())
115+
ServerResponse::SelfAddress(self.self_full_address)
116116
}
117117

118118
fn handle_request(&mut self, request: ClientRequest) -> Option<ServerResponse> {

clients/native/src/websocket/listener.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ enum State {
2828

2929
impl State {
3030
fn is_connected(&self) -> bool {
31-
match self {
32-
State::Connected => true,
33-
_ => false,
34-
}
31+
matches!(self, State::Connected)
3532
}
3633
}
3734

clients/native/websocket-requests/src/requests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ mod tests {
288288
let recipient_string = recipient.to_string();
289289

290290
let send_request_no_surb = ClientRequest::Send {
291-
recipient: recipient.clone(),
291+
recipient,
292292
message: b"foomp".to_vec(),
293293
with_reply_surb: false,
294294
};

clients/native/websocket-requests/src/responses.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,10 @@ impl ServerResponse {
310310
RECEIVED_RESPONSE_TAG => Self::deserialize_received(b),
311311
SELF_ADDRESS_RESPONSE_TAG => Self::deserialize_self_address(b),
312312
ERROR_RESPONSE_TAG => Self::deserialize_error(b),
313-
n => {
314-
return Err(error::Error::new(
315-
ErrorKind::UnknownResponse,
316-
format!("type {}", n),
317-
))
318-
}
313+
n => Err(error::Error::new(
314+
ErrorKind::UnknownResponse,
315+
format!("type {}", n),
316+
)),
319317
}
320318
}
321319

clients/socks5/src/client/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl NymClient {
7777
pub fn as_mix_recipient(&self) -> Recipient {
7878
Recipient::new(
7979
*self.key_manager.identity_keypair().public_key(),
80-
self.key_manager.encryption_keypair().public_key().clone(),
80+
*self.key_manager.encryption_keypair().public_key(),
8181
// TODO: below only works under assumption that gateway address == gateway id
8282
// (which currently is true)
8383
NodeIdentity::from_base58_string(self.config.get_base().get_gateway_id()).unwrap(),

clients/socks5/src/socks/client.rs

+4-19
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl SocksClient {
243243
let connection_id = self.connection_id;
244244
let input_sender = self.input_sender.clone();
245245

246-
let recipient = self.service_provider.clone();
246+
let recipient = self.service_provider;
247247
let (stream, _) = ProxyRunner::new(
248248
stream,
249249
local_stream_remote,
@@ -365,27 +365,12 @@ impl SocksClient {
365365

366366
// Username parsing
367367
let ulen = header[1];
368-
369-
let mut username = Vec::with_capacity(ulen as usize);
370-
371-
// For some reason the vector needs to actually be full
372-
for _ in 0..ulen {
373-
username.push(0);
374-
}
375-
368+
let mut username = vec![0; ulen as usize];
376369
self.stream.read_exact(&mut username).await?;
377370

378371
// Password Parsing
379-
let mut plen = [0u8; 1];
380-
self.stream.read_exact(&mut plen).await?;
381-
382-
let mut password = Vec::with_capacity(plen[0] as usize);
383-
384-
// For some reason the vector needs to actually be full
385-
for _ in 0..plen[0] {
386-
password.push(0);
387-
}
388-
372+
let plen = self.stream.read_u8().await?;
373+
let mut password = vec![0; plen as usize];
389374
self.stream.read_exact(&mut password).await?;
390375

391376
let username_str = String::from_utf8(username)?;

clients/socks5/src/socks/request.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::types::{AddrType, ResponseCode, SocksProxyError};
22
use super::{utils as socks_utils, SOCKS_VERSION};
33
use log::*;
4+
use std::fmt::{self, Display};
45
use tokio::prelude::*;
56

67
/// A Socks5 request hitting the proxy.
@@ -95,12 +96,14 @@ impl SocksRequest {
9596
port,
9697
})
9798
}
99+
}
98100

101+
impl Display for SocksRequest {
99102
/// Print out the address and port to a String.
100103
/// This might return domain:port, ipv6:port, or ipv4:port.
101-
pub(crate) fn to_string(&self) -> String {
104+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
102105
let address = socks_utils::pretty_print_addr(&self.addr_type, &self.addr);
103-
format!("{}:{}", address, self.port)
106+
write!(f, "{}:{}", address, self.port)
104107
}
105108
}
106109

clients/socks5/src/socks/server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ impl SphinxSocksServer {
7272
stream,
7373
self.authenticator.clone(),
7474
input_sender.clone(),
75-
self.service_provider.clone(),
75+
self.service_provider,
7676
controller_sender.clone(),
77-
self.self_address.clone(),
77+
self.self_address,
7878
);
7979

8080
tokio::spawn(async move {

common/client-libs/gateway-client/src/socket_state.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,14 @@ pub(crate) enum SocketState {
183183

184184
impl SocketState {
185185
pub(crate) fn is_available(&self) -> bool {
186-
match self {
187-
SocketState::Available(_) => true,
188-
_ => false,
189-
}
186+
matches!(self, SocketState::Available(_))
190187
}
191188

192189
pub(crate) fn is_partially_delegated(&self) -> bool {
193-
match self {
194-
SocketState::PartiallyDelegated(_) => true,
195-
_ => false,
196-
}
190+
matches!(self, SocketState::PartiallyDelegated(_))
197191
}
198192

199193
pub(crate) fn is_established(&self) -> bool {
200-
match self {
201-
SocketState::Available(_) | SocketState::PartiallyDelegated(_) => true,
202-
_ => false,
203-
}
194+
matches!(self, SocketState::Available(_) | SocketState::PartiallyDelegated(_))
204195
}
205196
}

common/client-libs/validator-client/src/models/gateway.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl TryInto<topology::gateway::Node> for RegisteredGateway {
104104
.node_info
105105
.mix_host
106106
.to_socket_addrs()
107-
.map_err(|err| ConversionError::InvalidAddress(err))?
107+
.map_err(ConversionError::InvalidAddress)?
108108
.next()
109109
.ok_or_else(|| {
110110
ConversionError::InvalidAddress(io::Error::new(

common/client-libs/validator-client/src/models/mixnode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl TryInto<topology::mix::Node> for RegisteredMix {
100100
.node_info
101101
.mix_host
102102
.to_socket_addrs()
103-
.map_err(|err| ConversionError::InvalidAddress(err))?
103+
.map_err(ConversionError::InvalidAddress)?
104104
.next()
105105
.ok_or_else(|| {
106106
ConversionError::InvalidAddress(io::Error::new(

common/client-libs/validator-client/src/models/topology.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Into<NymTopology> for Topology {
4747
}
4848
let mix_id = mix.mix_info.node_info.identity_key.clone();
4949

50-
let layer_entry = mixes.entry(layer).or_insert(Vec::new());
50+
let layer_entry = mixes.entry(layer).or_insert_with(Vec::new);
5151
match mix.try_into() {
5252
Ok(mix) => layer_entry.push(mix),
5353
Err(err) => {

common/crypto/src/asymmetric/identity/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use bs58;
1615
use ed25519_dalek::ed25519::signature::Signature as SignatureTrait;
1716
pub use ed25519_dalek::SignatureError;
1817
pub use ed25519_dalek::{Verifier, PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH, SIGNATURE_LENGTH};

common/mixnode-common/src/cached_packet_processor/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl KeyCache {
6767

6868
pub(super) fn insert(&self, key: SharedSecret, cached_keys: CachedKeys) -> bool {
6969
trace!("inserting {:?} into the cache", key);
70-
let insertion_result = self.vpn_key_cache.insert(key.clone(), cached_keys);
70+
let insertion_result = self.vpn_key_cache.insert(key, cached_keys);
7171
if !insertion_result {
7272
debug!("{:?} was put into the cache", key);
7373
// this shouldn't really happen, but don't insert entry to invalidator if it was already

common/mixnode-common/src/cached_packet_processor/processor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ mod tests {
352352
let initial_secret = final_hop.shared_secret();
353353
let processed = final_hop.process(&processor.sphinx_key).unwrap();
354354

355-
processor.cache_keys(initial_secret.clone(), &processed);
355+
processor.cache_keys(initial_secret, &processed);
356356
let cache_entry = processor.vpn_key_cache.get(&initial_secret).unwrap();
357357

358358
let (cached_secret, cached_routing_keys) = cache_entry.value();
@@ -376,7 +376,7 @@ mod tests {
376376
let initial_secret = forward_hop.shared_secret();
377377
let processed = forward_hop.process(&processor.sphinx_key).unwrap();
378378

379-
processor.cache_keys(initial_secret.clone(), &processed);
379+
processor.cache_keys(initial_secret, &processed);
380380
let cache_entry = processor.vpn_key_cache.get(&initial_secret).unwrap();
381381

382382
let (cached_secret, cached_routing_keys) = cache_entry.value();
@@ -463,7 +463,7 @@ mod tests {
463463

464464
let long_data = vec![42u8; SURBAck::len() * 5];
465465
let (ack, data) = processor
466-
.split_hop_data_into_ack_and_message(long_data.clone())
466+
.split_hop_data_into_ack_and_message(long_data)
467467
.unwrap();
468468
assert_eq!(ack.len(), SURBAck::len());
469469
assert_eq!(data.len(), SURBAck::len() * 4)

common/nymsphinx/acknowledgements/src/surb_ack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl SURBAck {
7474

7575
let expected_total_delay = delays.iter().sum();
7676
let first_hop_address =
77-
NymNodeRoutingAddress::try_from(route.first().unwrap().address.clone()).unwrap();
77+
NymNodeRoutingAddress::try_from(route.first().unwrap().address).unwrap();
7878

7979
Ok(SURBAck {
8080
surb_ack_packet,

common/nymsphinx/addressing/src/clients.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ impl<'de> Deserialize<'de> for Recipient {
102102
// this shouldn't panic as we just checked for length
103103
recipient_bytes.copy_from_slice(&bytes);
104104

105-
Recipient::try_from_bytes(recipient_bytes).or_else(|_| {
106-
Err(SerdeError::invalid_value(
105+
Recipient::try_from_bytes(recipient_bytes).map_err(|_| {
106+
SerdeError::invalid_value(
107107
Unexpected::Other("At least one of the curve points was malformed"),
108108
&self,
109-
))
109+
)
110110
})
111111
}
112112
}
@@ -251,7 +251,7 @@ mod tests {
251251

252252
let recipient = Recipient::new(
253253
*client_id_pair.public_key(),
254-
client_enc_pair.public_key().clone(),
254+
*client_enc_pair.public_key(),
255255
*gateway_id_pair.public_key(),
256256
);
257257

@@ -281,7 +281,7 @@ mod tests {
281281

282282
let recipient = Recipient::new(
283283
*client_id_pair.public_key(),
284-
client_enc_pair.public_key().clone(),
284+
*client_enc_pair.public_key(),
285285
*gateway_id_pair.public_key(),
286286
);
287287

common/nymsphinx/anonymous-replies/src/reply_surb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<'de> Deserialize<'de> for ReplySURB {
103103
E: SerdeError,
104104
{
105105
ReplySURB::from_bytes(bytes)
106-
.or_else(|_| Err(SerdeError::invalid_length(bytes.len(), &self)))
106+
.map_err(|_| SerdeError::invalid_length(bytes.len(), &self))
107107
}
108108
}
109109

common/nymsphinx/cover/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ where
146146
.unwrap();
147147

148148
let first_hop_address =
149-
NymNodeRoutingAddress::try_from(route.first().unwrap().address.clone()).unwrap();
149+
NymNodeRoutingAddress::try_from(route.first().unwrap().address).unwrap();
150150

151151
// if client is running in vpn mode, he won't even be sending cover traffic
152152
Ok(MixPacket::new(first_hop_address, packet, PacketMode::Mix))

common/nymsphinx/src/preparer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ where
321321

322322
// from the previously constructed route extract the first hop
323323
let first_hop_address =
324-
NymNodeRoutingAddress::try_from(route.first().unwrap().address.clone()).unwrap();
324+
NymNodeRoutingAddress::try_from(route.first().unwrap().address).unwrap();
325325

326326
Ok(PreparedFragment {
327327
// the round-trip delay is the sum of delays of all hops on the forward route as

common/nymsphinx/src/preparer/vpn_manager.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ impl VPNManager {
118118
}
119119

120120
#[cfg(not(target_arch = "wasm32"))]
121-
pub(super) async fn current_secret<'a>(&'a self) -> SpinhxKeyRef<'a> {
121+
pub(super) async fn current_secret(&self) -> SpinhxKeyRef<'_> {
122122
self.inner.current_initial_secret.read().await
123123
}
124124

125125
#[cfg(target_arch = "wasm32")]
126-
pub(super) async fn current_secret<'a>(&'a self) -> SpinhxKeyRef<'a> {
126+
pub(super) async fn current_secret(&self) -> SpinhxKeyRef<'_> {
127127
&self.inner.current_initial_secret
128128
}
129129

common/socks5/ordered-buffer/src/buffer.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,10 @@ impl OrderedMessageBuffer {
5050

5151
let mut contiguous_messages = Vec::new();
5252
let mut index = self.next_index;
53-
loop {
54-
if let Some(ordered_message) = self.messages.remove(&index) {
55-
contiguous_messages.push(ordered_message);
56-
index += 1;
57-
} else {
58-
break;
59-
}
53+
54+
while let Some(ordered_message) = self.messages.remove(&index) {
55+
contiguous_messages.push(ordered_message);
56+
index += 1;
6057
}
6158

6259
let high_water = index;

0 commit comments

Comments
 (0)