chiark / gitweb /
mime slip tests, currently failing
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 Aug 2021 18:38:20 +0000 (19:38 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 Aug 2021 18:38:39 +0000 (19:38 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/client.rs
src/slip.rs

index 1bac9c3fed5153293b5206a6d579f76a3f956922..d6ee158a967a4a27d776d1630a725ed0313d17c9 100644 (file)
@@ -209,7 +209,7 @@ async fn run_client<C:HCC>(
               .ok_or_else(|| io::Error::from(io::ErrorKind::UnexpectedEof))?;
 //            eprintln!("packet={:x?}", &packet);
             if let Ok(()) = check_checkmtu_mimeswap
-              ::<true>(&ic, &mut packet)
+              ::<true>(ic.mtu, &mut packet)
             {
               match upbound.add(ic.max_batch_up, packet) {
                 Err(packet) => {
index f4b23a51ef243b0f9073ae835ff4dc709d061fcb..f33bfc13a599a5964bfff8268cb21d0562e6a1b6 100644 (file)
@@ -8,13 +8,13 @@ pub static SLIP_END_SLICE: &[u8] = &[SLIP_END];
 
 #[throws(AE)]
 pub fn check_checkmtu_mimeswap<const TO_MIME: bool>
-  (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::<true>(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") );
+}