diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-12-16 17:36:57 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-12-16 17:36:57 +0000 |
| commit | c03281d1f8f856cfc68c2b06dede6b7306b4fea5 (patch) | |
| tree | ee7d10732669bcfb71e9c4ce240c00f8407231fb /src/path.rs | |
| parent | Getting closer to no-std being done (diff) | |
| download | meshcore-rs-main.tar.gz meshcore-rs-main.zip | |
Diffstat (limited to 'src/path.rs')
| -rw-r--r-- | src/path.rs | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/src/path.rs b/src/path.rs index a2eb1c9..a1aaedd 100644 --- a/src/path.rs +++ b/src/path.rs @@ -1,5 +1,5 @@ -use bytes::Bytes; use crate::packet_content::PeerToPeerCipher; +use bytes::Bytes; #[derive(PartialEq, Debug, Clone)] pub struct Path { @@ -9,25 +9,31 @@ pub struct Path { impl From<Bytes> for Path { fn from(value: Bytes) -> Self { Path { - cipher: PeerToPeerCipher::from(value) + cipher: PeerToPeerCipher::from(value), } } } impl core::fmt::Display for Path { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_fmt(format_args!("({:2x?}) -> ({:2x?}) MAC: {:4x?} ", self.cipher.source, self.cipher.destination, self.cipher.mac)) + f.write_fmt(format_args!( + "({:2x?}) -> ({:2x?}) MAC: {:4x?} ", + self.cipher.source, self.cipher.destination, self.cipher.mac + )) } } // Tests for std operations #[cfg(test)] mod tests { + use crate::{ + packet::*, + packet_content::{PacketContent, PeerToPeerCipher}, + }; use core::str::FromStr; use hex::decode; use tinyvec::array_vec; - use crate::{packet::*, packet_content::{PacketContent, PeerToPeerCipher}}; - + use super::*; #[test] @@ -39,23 +45,32 @@ mod tests { version: PayloadVersion::VersionOne, path: array_vec!([u16; 64] => 0xBA, 0x03, 0x12, 0x7F, 0x7E, 0xA9, 0x22), transport: [0, 0], - raw_content: Bytes::copy_from_slice(&decode("1351768DD2DF32E1D02F5851379F5AFCC667AB273442FAB2943673F26DDBEB9595027474").unwrap()), + raw_content: Bytes::copy_from_slice( + &decode("1351768DD2DF32E1D02F5851379F5AFCC667AB273442FAB2943673F26DDBEB9595027474") + .unwrap(), + ), content: PacketContent::Path(Path { cipher: PeerToPeerCipher { destination: 0x13, source: 0x51, mac: 0x768D, - ciphertext: Bytes::copy_from_slice(&decode("D2DF32E1D02F5851379F5AFCC667AB273442FAB2943673F26DDBEB9595027474").unwrap()), - cleartext: None - } + ciphertext: Bytes::copy_from_slice( + &decode("D2DF32E1D02F5851379F5AFCC667AB273442FAB2943673F26DDBEB9595027474") + .unwrap(), + ), + cleartext: None, + }, }), - incomplete: false + incomplete: false, }; let rhs_packet = Packet::from_str(sample).unwrap(); assert_eq!(lhs_packet, rhs_packet); #[cfg(feature = "std")] - assert_eq!(format!("{}", lhs_packet), " Flood | v1 | | [ba, 03, ... a9, 22] | | PATH | (51) -> (13) MAC: 768d "); + assert_eq!( + format!("{}", lhs_packet), + " Flood | v1 | | [ba, 03, ... a9, 22] | | PATH | (51) -> (13) MAC: 768d " + ); } -}
\ No newline at end of file +} |
