aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWill Dillon <william@housedillon.com>2025-11-06 08:50:26 +0000
committerWill Dillon <william@housedillon.com>2025-11-06 08:50:26 +0000
commitbbc92dc97ef2ad086ce1f8181b711c617bea3280 (patch)
treedbd7933538be5efb8c6fdf6888b39948c4df8bc4 /src
parentAll the packet types pass tests (diff)
downloadmeshcore-rs-bbc92dc97ef2ad086ce1f8181b711c617bea3280.tar.gz
meshcore-rs-bbc92dc97ef2ad086ce1f8181b711c617bea3280.zip
Ran clippy
Diffstat (limited to 'src')
-rw-r--r--src/crypto.rs10
-rw-r--r--src/packet.rs53
2 files changed, 30 insertions, 33 deletions
diff --git a/src/crypto.rs b/src/crypto.rs
index 71c1cb3..9dd423b 100644
--- a/src/crypto.rs
+++ b/src/crypto.rs
@@ -1,8 +1,8 @@
-use std::{array::TryFromSliceError, collections::HashMap, str::FromStr};
+use std::str::FromStr;
use ed25519_dalek::hazmat::ExpandedSecretKey;
use curve25519_dalek::{constants, edwards::CompressedEdwardsY};
-use tokio_util::bytes::{self, Buf, Bytes};
+use tokio_util::bytes::{Buf, Bytes};
use x25519_dalek::StaticSecret;
use hex::decode;
@@ -23,7 +23,7 @@ pub struct SharedSecret([u8; 32]);
// This is just for creating placeholders
impl Default for PublicKey {
fn default() -> Self {
- PublicKey(CompressedEdwardsY::from_slice(&[0 as u8; 32]).unwrap())
+ PublicKey(CompressedEdwardsY::from_slice(&[0_u8; 32]).unwrap())
}
}
@@ -35,9 +35,9 @@ impl TryFrom<Bytes> for PublicKey {
return Err(MeshcoreCryptoError::TryFromSliceError)
}
- let mut slice = [0 as u8; 32];
+ let mut slice = [0_u8; 32];
- if let Err(_) = value.try_copy_to_slice(&mut slice) {
+ if value.try_copy_to_slice(&mut slice).is_err() {
return Err(MeshcoreCryptoError::TryFromSliceError)
}
diff --git a/src/packet.rs b/src/packet.rs
index ad79688..4325e10 100644
--- a/src/packet.rs
+++ b/src/packet.rs
@@ -171,11 +171,11 @@ struct Request {
impl From<Bytes> for Request {
fn from(value: Bytes) -> Self {
- let request = Request {
- cipher: PeerToPeerCipher::from(value)
- };
+
- request
+ Request {
+ cipher: PeerToPeerCipher::from(value)
+ }
}
}
@@ -187,11 +187,11 @@ struct Response {
impl From<Bytes> for Response {
fn from(value: Bytes) -> Self {
- let response = Response {
- cipher: PeerToPeerCipher::from(value)
- };
+
- response
+ Response {
+ cipher: PeerToPeerCipher::from(value)
+ }
}
}
@@ -240,7 +240,7 @@ impl From<Bytes> for Advert {
let mut advert = Advert {
public_key: PublicKey::default(),
timestamp: Local::now().into(),
- signature: [0 as u8; 64],
+ signature: [0_u8; 64],
node_type: NodeType::Invalid,
latitude: None,
@@ -265,7 +265,7 @@ impl From<Bytes> for Advert {
if bytes.len() < 64 { return advert }
_ = bytes.try_copy_to_slice(&mut advert.signature);
- if bytes.len() == 0 { return advert }
+ if bytes.is_empty() { return advert }
let flags = bytes.get_u8();
advert.node_type = NodeType::from(flags);
@@ -374,7 +374,7 @@ impl From<Bytes> for AnonReq {
incomplete: false,
};
- if bytes.len() == 0 { return anon_req; }
+ if bytes.is_empty() { return anon_req; }
anon_req.destination = bytes.get_u8();
if bytes.len() < 32 { return anon_req; }
@@ -433,7 +433,7 @@ impl From<Bytes> for Trace {
trace.tag = bytes.get_u32();
trace.auth = bytes.get_u32();
trace.flags = bytes.get_u8();
- trace.temp_path = bytes.iter().map(|s| *s).collect();
+ trace.temp_path = bytes.iter().copied().collect();
trace.invalid = false;
trace
}
@@ -497,7 +497,7 @@ impl From<Bytes> for Packet {
};
// Get the route
- if bytes.len() == 0 { return packet; }
+ if bytes.is_empty() { return packet; }
let path_length = bytes.get_u8() as usize;
packet.path = match packet.version {
@@ -514,7 +514,7 @@ impl From<Bytes> for Packet {
},
PayloadVersion::VersionTwo => {
// The packet isn't long enough for the indicated route
- if bytes.len() < path_length as usize * 2 { return packet; }
+ if bytes.len() < path_length * 2 { return packet; }
let route: Vec<u16> = bytes
.split_to(path_length * 2)
@@ -536,20 +536,17 @@ impl From<Bytes> for Packet {
// Unfortunately, the trace packet is a bit weird.
// So, if this is a trace packet, move things back into the right place.
- match packet.content {
- PacketContent::Trace(trace) => {
- let mut trace = trace;
- let path_snr = packet.path;
- packet.path = trace.temp_path.iter().map(|i| *i as u16).collect();
- trace.path_snr = path_snr.iter().map( |u| {
- let i = *u as i8;
- let f = i as f32;
- f / 4.0
- }).collect();
- trace.temp_path = vec![];
- packet.content = PacketContent::Trace(trace);
- },
- _ => {}
+ if let PacketContent::Trace(trace) = packet.content {
+ let mut trace = trace;
+ let path_snr = packet.path;
+ packet.path = trace.temp_path.iter().map(|i| *i as u16).collect();
+ trace.path_snr = path_snr.iter().map( |u| {
+ let i = *u as i8;
+ let f = i as f32;
+ f / 4.0
+ }).collect();
+ trace.temp_path = vec![];
+ packet.content = PacketContent::Trace(trace);
}
// Mark the packet as complete and valid