Skip to main content

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
15#[cfg(feature = "static_assertions")]
16static_assertions::assert_impl_all!(Action: Send);
17
18/// Result of the ES subsystem authorization process.
19///
20/// See also [`Action`].
21#[doc(alias = "es_result_t")]
22#[doc(alias = "es_result_type_t")]
23#[doc(alias = "es_auth_result_t")]
24#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
25pub enum ActionResult {
26    /// Result of an `AUTH` action
27    Auth(es_auth_result_t),
28    /// Flags resulting of an action
29    Flags(u32),
30}
31
32impl ActionResult {
33    /// Build [`Self`] from the raw result
34    pub(crate) fn from_raw(r: es_result_t) -> Option<Self> {
35        match r.result_type {
36            // Safety: we just checked the `result_type` member
37            es_result_type_t::ES_RESULT_TYPE_AUTH => Some(Self::Auth(unsafe { r.result.auth })),
38            // Safety: we just checked the `result_type` member
39            es_result_type_t::ES_RESULT_TYPE_FLAGS => Some(Self::Flags(unsafe { r.result.flags })),
40            _ => None,
41        }
42    }
43}
44
45#[cfg(feature = "static_assertions")]
46static_assertions::assert_impl_all!(ActionResult: Send);