Skip to main content

liminal_protocol/wire/
envelope.rs

1use super::{
2    AttachAttemptToken, ClientDiscriminant, ConversationId, DeliverySeq, DetachAttemptToken,
3    EnrollmentToken, Generation, LeaveAttemptToken, ParticipantId, RecordAdmissionAttemptToken,
4};
5
6/// Enrollment response common envelope.
7#[derive(Clone, Debug, PartialEq, Eq)]
8pub struct EnrollmentEnvelope {
9    /// Conversation from the request.
10    pub conversation_id: ConversationId,
11    /// Enrollment token from the request.
12    pub enrollment_token: EnrollmentToken,
13}
14
15/// Credential-attach response common envelope; the secret is deliberately absent.
16#[derive(Clone, Debug, PartialEq, Eq)]
17pub struct AttachEnvelope {
18    /// Conversation from the request.
19    pub conversation_id: ConversationId,
20    /// Participant from the request.
21    pub participant_id: ParticipantId,
22    /// Presented generation.
23    pub capability_generation: Generation,
24    /// Attach token from the request.
25    pub attach_attempt_token: AttachAttemptToken,
26    /// Presented marker option.
27    pub accept_marker_delivery_seq: Option<DeliverySeq>,
28}
29
30/// Detach response common envelope.
31#[derive(Clone, Debug, PartialEq, Eq)]
32pub struct DetachEnvelope {
33    /// Conversation from the request.
34    pub conversation_id: ConversationId,
35    /// Participant from the request.
36    pub participant_id: ParticipantId,
37    /// Presented generation.
38    pub capability_generation: Generation,
39    /// Detach token from the request.
40    pub detach_attempt_token: DetachAttemptToken,
41}
42
43/// Continuous-ack response common envelope.
44#[derive(Clone, Debug, PartialEq, Eq)]
45pub struct ParticipantAckEnvelope {
46    /// Conversation from the request.
47    pub conversation_id: ConversationId,
48    /// Participant from the request.
49    pub participant_id: ParticipantId,
50    /// Presented generation.
51    pub capability_generation: Generation,
52    /// Requested cumulative boundary.
53    pub through_seq: DeliverySeq,
54}
55
56/// Leave response common envelope; the secret is deliberately absent.
57#[derive(Clone, Debug, PartialEq, Eq)]
58pub struct LeaveEnvelope {
59    /// Conversation from the request.
60    pub conversation_id: ConversationId,
61    /// Participant from the request.
62    pub participant_id: ParticipantId,
63    /// Presented generation.
64    pub capability_generation: Generation,
65    /// Leave token from the request.
66    pub leave_attempt_token: LeaveAttemptToken,
67}
68
69/// Marker-ack response common envelope.
70#[derive(Clone, Debug, PartialEq, Eq)]
71pub struct MarkerAckEnvelope {
72    /// Conversation from the request.
73    pub conversation_id: ConversationId,
74    /// Participant from the request.
75    pub participant_id: ParticipantId,
76    /// Presented generation.
77    pub capability_generation: Generation,
78    /// Requested marker sequence.
79    pub marker_delivery_seq: DeliverySeq,
80}
81
82/// Ordinary-admission response common envelope; payload is deliberately absent.
83#[derive(Clone, Debug, PartialEq, Eq)]
84pub struct RecordAdmissionEnvelope {
85    /// Conversation from the request.
86    pub conversation_id: ConversationId,
87    /// Participant from the request.
88    pub participant_id: ParticipantId,
89    /// Presented generation.
90    pub capability_generation: Generation,
91    /// Client-selected request-attempt identity echoed by every terminal response.
92    pub record_admission_attempt_token: RecordAdmissionAttemptToken,
93}
94
95/// Exact operation-specific response envelope for requests `0x0001..=0x0007`.
96#[derive(Clone, Debug, PartialEq, Eq)]
97pub enum ResponseEnvelope {
98    /// Enrollment envelope.
99    Enrollment(EnrollmentEnvelope),
100    /// Credential-attach envelope.
101    CredentialAttach(AttachEnvelope),
102    /// Detach envelope.
103    Detach(DetachEnvelope),
104    /// Continuous-ack envelope.
105    ParticipantAck(ParticipantAckEnvelope),
106    /// Leave envelope.
107    Leave(LeaveEnvelope),
108    /// Marker-ack envelope.
109    MarkerAck(MarkerAckEnvelope),
110    /// Ordinary-admission envelope.
111    RecordAdmission(RecordAdmissionEnvelope),
112}
113
114impl ResponseEnvelope {
115    /// Returns the structural `originating_request` selector.
116    #[must_use]
117    pub const fn originating_request(&self) -> ClientDiscriminant {
118        match self {
119            Self::Enrollment(_) => ClientDiscriminant::EnrollmentRequest,
120            Self::CredentialAttach(_) => ClientDiscriminant::CredentialAttachRequest,
121            Self::Detach(_) => ClientDiscriminant::DetachRequest,
122            Self::ParticipantAck(_) => ClientDiscriminant::ParticipantAck,
123            Self::Leave(_) => ClientDiscriminant::LeaveRequest,
124            Self::MarkerAck(_) => ClientDiscriminant::MarkerAck,
125            Self::RecordAdmission(_) => ClientDiscriminant::RecordAdmission,
126        }
127    }
128}