"regex",
"sha2",
"structopt",
+ "thiserror",
"tokio",
"void",
]
"unicode-width",
]
+[[package]]
+name = "thiserror"
+version = "1.0.26"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.26"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
[[package]]
name = "tokio"
version = "1.8.2"
pub use lazy_regex::{regex_is_match, regex_replace_all};
pub use log::{debug, info, error};
pub use structopt::StructOpt;
+pub use thiserror::Error;
pub use tokio::io::AsyncBufReadExt;
pub use tokio::pin;
pub use tokio::select;
pub static SLIP_END_SLICE: &[u8] = &[SLIP_END];
-#[throws(AE)]
+#[derive(Error,Debug,Copy,Clone)]
+pub enum PacketError {
+ #[error("MTU exceeded ({len} > {mtu})")] MTU { len: usize, mtu: u32 },
+ #[error("Invalid SLIP escape sequence")] SLIP,
+}
+
+#[throws(PacketError)]
pub fn check_checkmtu_mimeswap<const TO_MIME: bool>
(mtu: u32, data: &mut [u8])
{
for mut packet in data.split_mut(|&c| c == SLIP_END) {
if packet.len() > mtu.sat() {
- throw!(anyhow!("MTU exceeded ({} > {})", packet.len(), mtu));
+ throw!(PacketError::MTU { len: packet.len(), mtu })
}
while let Some((i, was_mime)) = packet.iter().enumerate().find_map(
match packet.get(i+1) {
Some(&SLIP_ESC_END) |
Some(&SLIP_ESC_ESC) => Ok(()),
- _ => Err(anyhow!("SLIP escape not followed by ESC_END or ESC_ESC")),
+ _ => throw!(PacketError::SLIP),
}?;
packet = &mut packet[i+2 ..];
} else {