1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! [`Acl`] is wrapper around ACLs received from Endpoint Security.
//!
//! **Important**: ACLs generated by Endpoint Security are **not** directly compatible
//! with `sys/acl.h`, be sure to check up-to-date documentation for your macOS target.

use endpoint_sec_sys::{_acl, acl_t};

/// ACL from Endpoint Security.
// **DO NOT USE DIRECTLY WITH `sys/acl.h`**
// TODO: correctly implement Debug/Eq/Hash for ACLs
#[doc(alias = "acl_t")]
#[doc(alias = "_acl")]
pub struct Acl<'a>(&'a _acl);

impl<'a> Acl<'a> {
    /// Builds an ACL wrapper from the raw one.
    ///
    /// `None` if the given ACL is NULL inside.
    pub(crate) fn from_raw(r: acl_t) -> Option<Self> {
        // Safety: let's hope Apple gave us an aligned and initialized pointer
        unsafe { r.as_ref() }.map(Self)
    }

    // NOTE: in the future, if we need to interact with `sys/acl.h`, remember to read the docs
    // in ESMessage.h, there are details to the way it should be done.
}

static_assertions::assert_impl_all!(Acl<'_>: Send);

impl_debug_eq_hash_with_functions!(Acl<'a>;);