endpoint_sec/
action.rs

1//! Actions associated with a [`Message`][crate::Message].
2
3use endpoint_sec_sys::{es_auth_result_t, es_event_id_t, es_result_t, es_result_type_t};
4
5/// When a [`Message`][crate::Message] is received, it is associated with an `Action`
6#[doc(alias = "es_event_id_t")]
7#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
8pub enum Action {
9    /// For `AUTH` events, it is the opaque ID that must be supplied when responding
10    Auth(es_event_id_t),
11    /// For `NOTIFY` events, describes the result of the action
12    Notify(ActionResult),
13}
14
15static_assertions::assert_impl_all!(Action: Send);
16
17/// Result of the ES subsystem authorization process.
18///
19/// See also [`Action`].
20#[doc(alias = "es_result_t")]
21#[doc(alias = "es_result_type_t")]
22#[doc(alias = "es_auth_result_t")]
23#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
24pub enum ActionResult {
25    /// Result of an `AUTH` action
26    Auth(es_auth_result_t),
27    /// Flags resulting of an action
28    Flags(u32),
29}
30
31impl ActionResult {
32    /// Build [`Self`] from the raw result
33    pub(crate) fn from_raw(r: es_result_t) -> Option<Self> {
34        match r.result_type {
35            // Safety: we just checked the `result_type` member
36            es_result_type_t::ES_RESULT_TYPE_AUTH => Some(Self::Auth(unsafe { r.result.auth })),
37            // Safety: we just checked the `result_type` member
38            es_result_type_t::ES_RESULT_TYPE_FLAGS => Some(Self::Flags(unsafe { r.result.flags })),
39            _ => None,
40        }
41    }
42}
43
44static_assertions::assert_impl_all!(ActionResult: Send);