feat: drop unknown typed frames instead of storing as chat
Classify decrypted plaintext before append_message so loc/prf/inv/rcp/png and unknown xxx[space] prefixes never land in the message log.
This commit is contained in:
parent
cbbf3f6baa
commit
c9d85d9ae5
4 changed files with 105 additions and 18 deletions
39
src/dispatch.rs
Normal file
39
src/dispatch.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
//! Classify decrypted application plaintext before it hits the message log.
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Kind {
|
||||
Chat,
|
||||
Loc,
|
||||
Profile,
|
||||
Invoice,
|
||||
Receipt,
|
||||
Ping,
|
||||
Drop,
|
||||
}
|
||||
|
||||
pub fn classify(pt: &[u8]) -> Kind {
|
||||
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"png ") {
|
||||
return Kind::Ping;
|
||||
}
|
||||
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
|
||||
}
|
||||
Loading…
Reference in a new issue