From: Ian Jackson Date: Sun, 1 Aug 2021 18:38:20 +0000 (+0100) Subject: mime slip tests, currently failing X-Git-Tag: hippotat/1.0.0~393 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=2330496313b9d2396057c3537051e64a7991a51c;p=hippotat.git mime slip tests, currently failing Signed-off-by: Ian Jackson --- diff --git a/src/bin/client.rs b/src/bin/client.rs index 1bac9c3..d6ee158 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -209,7 +209,7 @@ async fn run_client( .ok_or_else(|| io::Error::from(io::ErrorKind::UnexpectedEof))?; // eprintln!("packet={:x?}", &packet); if let Ok(()) = check_checkmtu_mimeswap - ::(&ic, &mut packet) + ::(ic.mtu, &mut packet) { match upbound.add(ic.max_batch_up, packet) { Err(packet) => { diff --git a/src/slip.rs b/src/slip.rs index f4b23a5..f33bfc1 100644 --- a/src/slip.rs +++ b/src/slip.rs @@ -8,13 +8,13 @@ pub static SLIP_END_SLICE: &[u8] = &[SLIP_END]; #[throws(AE)] pub fn check_checkmtu_mimeswap - (ic: &InstanceConfig, data: &mut [u8]) + (mtu: u32, data: &mut [u8]) { // eprintln!("before: {}", DumpHex(data)); for mut packet in data.split_mut(|&c| c == SLIP_END) { - if packet.len() > ic.mtu.sat() { - throw!(anyhow!("mtu exceeded ({} > {})", packet.len(), ic.mtu)); + if packet.len() > mtu.sat() { + throw!(anyhow!("mtu exceeded ({} > {})", packet.len(), mtu)); } while let Some((i, _)) = packet.iter().enumerate().find( @@ -71,3 +71,20 @@ impl Display for DumpHex<'_> { for v in self.0 { write!(f, "{:02x}", v)?; } } } + +#[test] +fn mime_slip_to_mime() { + fn chk(i: &[u8], exp: Result<&[u8], &str>) { + let mut p = i.to_owned(); + match (exp, check_checkmtu_mimeswap::(10, p.as_mut())) { + (Ok(exp), Ok(())) => assert_eq!( exp, &p ), + (Err(exp), Err(got)) => assert!( got.to_string().contains(exp) ), + x => panic!("? {:?}", x), + } + } + + chk( &[ SLIP_END, SLIP_ESC, SLIP_ESC_END, b'-', b'X' ], + Ok(&[ SLIP_END, b'-', SLIP_ESC_END, SLIP_ESC, b'X' ]) ); + + chk( &[ SLIP_END, SLIP_ESC, b'y' ], Err("SLIP escape") ); +}