Skip to main content

zaun_community_protocol/crypto/
context.rs

1//! Signature contexts (specification §3.5).
2
3/// Whether a context is part of v1 conformance.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum ContextStatus {
6    /// Defined and used by protocol version 1.
7    V1,
8    /// Experimental (Appendix A); not part of v1 conformance.
9    Experimental,
10    /// Reserved for a later milestone; v1 implementations do not produce it.
11    Reserved,
12}
13
14/// An RFC 10073 `ctx` value of this protocol (specification §3.5). The verifier always
15/// supplies the context of the object type it expects; it is never read from the input.
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
17pub enum Context {
18    /// `CommunityDescriptor`, signed by the root key.
19    Descriptor,
20    /// `HostDelegation`, signed by the root key.
21    Delegation,
22    /// `RootRotation`, signed by the old and the new root key.
23    RootRotation,
24    /// `MemberKeyRegistration`, signed by the member key.
25    MemberKey,
26    /// `HostSessionProof`, signed by the host key.
27    HostSession,
28    /// `PublicCheckpoint`, signed by the host key. Experimental.
29    Checkpoint,
30    /// `MemberReauth`, signed by the member key (migration).
31    MemberReauth,
32    /// `ExportManifest`, signed by the host key (ADR-0013).
33    ExportManifest,
34    /// `VerificationAssertion`, signed by a verifier key. Reserved.
35    Verification,
36    /// `VoiceKeyPackage`, signed by the member key (ADR-0018). Experimental.
37    VoiceKeyPackage,
38    /// `VoiceSenderKeys`, signed by the member key (ADR-0018). Experimental.
39    VoiceSenderKeys,
40    /// `BotPackage`, signed by a publisher key (ADR-0019, §4.9).
41    BotPackage,
42}
43
44impl Context {
45    /// Every context, in the order of the §3.5 table.
46    pub const ALL: [Self; 12] = [
47        Self::Descriptor,
48        Self::Delegation,
49        Self::RootRotation,
50        Self::MemberKey,
51        Self::HostSession,
52        Self::Checkpoint,
53        Self::MemberReauth,
54        Self::ExportManifest,
55        Self::Verification,
56        Self::VoiceKeyPackage,
57        Self::VoiceSenderKeys,
58        Self::BotPackage,
59    ];
60
61    /// The ASCII `ctx` bytes.
62    #[must_use]
63    pub const fn as_bytes(self) -> &'static [u8] {
64        match self {
65            Self::Descriptor => b"zaun/v1/descriptor",
66            Self::Delegation => b"zaun/v1/delegation",
67            Self::RootRotation => b"zaun/v1/root-rotation",
68            Self::MemberKey => b"zaun/v1/member-key",
69            Self::HostSession => b"zaun/v1/host-session",
70            Self::Checkpoint => b"zaun/v1/checkpoint",
71            Self::MemberReauth => b"zaun/v1/member-reauth",
72            Self::ExportManifest => b"zaun/v1/export-manifest",
73            Self::Verification => b"zaun/v1/verification",
74            Self::VoiceKeyPackage => b"zaun/v1/voice-key-package",
75            Self::VoiceSenderKeys => b"zaun/v1/voice-sender-keys",
76            Self::BotPackage => b"zaun/v1/bot-package",
77        }
78    }
79
80    /// The status column of the §3.5 table.
81    #[must_use]
82    pub const fn status(self) -> ContextStatus {
83        match self {
84            Self::Descriptor
85            | Self::Delegation
86            | Self::RootRotation
87            | Self::MemberKey
88            | Self::HostSession
89            | Self::MemberReauth
90            | Self::ExportManifest
91            | Self::BotPackage => ContextStatus::V1,
92            Self::Checkpoint | Self::VoiceKeyPackage | Self::VoiceSenderKeys => {
93                ContextStatus::Experimental
94            }
95            Self::Verification => ContextStatus::Reserved,
96        }
97    }
98}