diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -1128,4 +1128,50 @@ mod tests { ); Ok(()) } + + #[test] + fn test_serialize_chap_response() -> Result<()> { + let response = PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + 1, + PppPkt::new_chap(ChapPkt::new_response(0x41, vec![0x13, 0x37], "foo".into())), + ); + + let mut buf = Vec::new(); + response.serialize(&mut buf)?; + + assert_eq!( + &buf, + &[ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x0c, 0xc2, 0x23, 0x02, 0x41, 0x00, 0x0a, 0x02, 0x13, + 0x37, 0x66, 0x6f, 0x6f + ] + ); + Ok(()) + } + + #[test] + fn test_deserialize_chap_response() -> Result<()> { + let mut response = PppoePkt::default(); + + let buf = [ + 0x00, 0x00, 0x5e, 0x00, 0x53, 0x01, 0x00, 0x00, 0x5e, 0x00, 0x53, 0x02, 0x88, 0x64, + 0x11, 0x00, 0x00, 0x01, 0x00, 0x0c, 0xc2, 0x23, 0x01, 0x41, 0x00, 0x0a, 0x02, 0x13, + 0x37, 0x66, 0x6f, 0x6f, + ]; + response.deserialize(&mut buf.as_ref())?; + + assert_eq!( + response, + PppoePkt::new_ppp( + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x01].into(), + [0x00, 0x00, 0x5e, 0x00, 0x53, 0x02].into(), + 1, + PppPkt::new_chap(ChapPkt::new_response(0x41, vec![0x13, 0x37], "foo".into())) + ) + ); + Ok(()) + } } |