Skip to main content

gent_protocol/
transport_sweep.rs

1//! One conditional read for the incoming mailboxes selected by a repair sweep.
2use serde::{Deserialize, Serialize};
3
4pub const ROUTE: &str = "/v2/mailbox-sweep";
5pub const LIMIT: usize = 32;
6pub const MAX_BYTES: usize = 20 * 1024;
7
8#[derive(Serialize, Deserialize)]
9#[serde(deny_unknown_fields)]
10pub struct Cursor {
11    pub mailbox: String,
12    pub next: u64,
13    /// SHA-256 of the canonical signed receipt encoded in standard Base64.
14    pub checkpoint_hash: String,
15}
16
17impl Cursor {
18    pub fn valid(&self) -> bool {
19        !self.mailbox.is_empty()
20            && self.mailbox.len() <= 384
21            && self
22                .mailbox
23                .bytes()
24                .all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_')
25            && self.next < 1 << 53
26            && self.checkpoint_hash.len() == 64
27            && self
28                .checkpoint_hash
29                .bytes()
30                .all(|b| b.is_ascii_hexdigit() && !b.is_ascii_uppercase())
31    }
32}
33
34/// A bit per request cursor, in the same order. The sender still needs a
35/// verified signed receipt before it can retire any ciphertext.
36#[derive(Default, Serialize, Deserialize)]
37#[serde(deny_unknown_fields)]
38pub struct Changes {
39    pub packets: u32,
40    pub checkpoints: u32,
41}