Skip to main content

coven_format/
device_gone.rs

1//! The marker a device gone for good leaves among its join requests (D8, D10).
2
3use crate::error::{exact_length, Error};
4
5/// What an admin's device creates at `<store>/join-requests/<device>/gone`
6/// once it applies the entry that stopped `<device>` for good, before it
7/// deletes the requests waiting there (ยง13.2). A joining device that finds
8/// it, before sending its request or while its request waits, ends its join
9/// as declined. It is never deleted: a request can arrive at any time, and
10/// the device it waits for never will answer. It holds nothing but its kind
11/// and format.
12#[derive(Clone, Copy, Debug, PartialEq, Eq)]
13pub struct DeviceGone;
14
15const KIND: u8 = crate::kinds::GONE_DEVICE;
16const LENGTH: usize = 3;
17
18impl DeviceGone {
19    /// The marker's complete bytes: its kind and format.
20    pub fn encode(&self) -> Vec<u8> {
21        crate::FormatVersion::CURRENT.prefix(KIND).to_vec()
22    }
23
24    /// Read a marker. Bytes of another kind, such as a join request or an
25    /// ended invite's marker, fail with `UnknownTag`.
26    pub fn decode(bytes: &[u8]) -> Result<Self, Error> {
27        crate::sealed::prefix(bytes, KIND)?;
28        exact_length(bytes.len(), LENGTH)?;
29        Ok(Self)
30    }
31}
32
33#[cfg(test)]
34#[path = "device_gone_tests.rs"]
35mod tests;