//! Classify decrypted application plaintext before it hits the message log. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Kind { Chat, Loc, Profile, Invoice, Receipt, Tip, Ping, File, /// Double Ratchet frame (`rat `, `src/ratchet.rs`). Chat travels as a /// ratchet frame; the plaintext only exists after decryption. Ratchet, Drop, } pub fn classify(pt: &[u8]) -> Kind { // Before the `[a-z]{3} ` catch-all below, which would drop it as unknown. if pt.starts_with(crate::ratchet::FRAME_PREFIX) { return Kind::Ratchet; } if pt.starts_with(b"loc ") { return Kind::Loc; } if pt.starts_with(b"prf ") { return Kind::Profile; } if pt.starts_with(b"inv ") { return Kind::Invoice; } if pt.starts_with(b"rcp ") { return Kind::Receipt; } if pt.starts_with(b"tip ") { return Kind::Tip; } if pt.starts_with(b"png ") { return Kind::Ping; } if pt.starts_with(b"fil ") { return Kind::File; } if pt.len() >= 4 && pt[0].is_ascii_lowercase() && pt[1].is_ascii_lowercase() && pt[2].is_ascii_lowercase() && pt[3] == b' ' { return Kind::Drop; } Kind::Chat }