Chat plaintext is ratchet-encrypted once, before the first delivery attempt,
and the frame is what the outbox stores and retries, so a retried message
re-sends identical bytes instead of advancing the sending chain twice.
- dispatch: Kind::Ratchet for the `rat ` prefix, matched before the unknown
[a-z]{3} prefix rule
- node: encode_chat_frame / ingest_chat_frame (the wire halves of Node::send
and handle_incoming), bootstrap derived from the peers' static prekey DH
because the Noise handshake is frozen and carries no ratchet key
- outbox: nullable outbox.payload + Outbox::send_payload; NULL payload keeps
the previous row-for-row behaviour
- store: additive outbox.payload migration, enqueue_outbox_payload,
OutboxEntry::payload
- add_friend_payload: a changed prekey clears the (prekey-bound) ratchet state
tests/ratchet_wire.rs (5) covers one frame per send, byte-identical retries,
out-of-order delivery, replay, tampering and fresh-friend both directions.
tests/tui_spec.rs and crates/onionwire-sdk/src/lib.rs only gained a
`payload: None` field in their OutboxEntry test fixtures: the card's required
field on a pub struct cannot be added without it.
54 lines
1.3 KiB
Rust
54 lines
1.3 KiB
Rust
//! 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
|
|
}
|