use crate::packet_content::PeerToPeerCipher; use bytes::Bytes; #[derive(PartialEq, Debug, Clone)] pub struct Path { pub cipher: PeerToPeerCipher, } impl From for Path { fn from(value: Bytes) -> Self { Path { 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 )) } } // 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 super::*; #[test] fn path() { let sample = "2107BA03127F7EA9221351768DD2DF32E1D02F5851379F5AFCC667AB273442FAB2943673F26DDBEB9595027474"; let lhs_packet = Packet { route_type: RouteType::Flood, 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(), ), content: PacketContent::Path(Path { cipher: PeerToPeerCipher { destination: 0x13, source: 0x51, mac: 0x768D, ciphertext: Bytes::copy_from_slice( &decode("D2DF32E1D02F5851379F5AFCC667AB273442FAB2943673F26DDBEB9595027474") .unwrap(), ), cleartext: None, }, }), 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 " ); } }