//! [`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>(#[allow(unused)] &'a _acl);

impl Acl<'_> {
    /// 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.
}

#[cfg(feature = "static_assertions")]
static_assertions::assert_impl_all!(Acl<'_>: Send);

impl_debug_eq_hash_with_functions!(Acl<'a>;);
