Skip to main content

endpoint_sec/event/
event_tcc_modify.rs

1//! [`EventTccModify`]
2
3use std::ffi::OsStr;
4
5use endpoint_sec_sys::{es_event_tcc_modify_t, es_tcc_identity_type_t, es_tcc_event_type_t, es_tcc_authorization_right_t, es_tcc_authorization_reason_t};
6
7use crate::{AuditToken, Process};
8
9/// TCC Modification Event.
10///
11/// Occurs when a TCC permission is granted or revoked.
12///
13/// Note: This event type does not support caching.
14#[doc(alias = "es_event_tcc_modify_t")]
15pub struct EventTccModify<'a> {
16    /// Raw event
17    pub(super) raw: &'a es_event_tcc_modify_t,
18    /// Message version
19    pub(crate) version: u32,
20}
21
22impl<'a> EventTccModify<'a> {
23    /// The TCC service for which permissions are being modified.
24    #[inline(always)]
25    pub fn service(&self) -> &'a OsStr {
26        // Safety: 'a tied to self, object obtained through ES
27        unsafe { self.raw.service.as_os_str() }
28    }
29
30    /// The identity of the application that is the subject of the permission.
31    #[inline(always)]
32    pub fn identity(&self) -> &'a OsStr {
33        // Safety: 'a tied to self, object obtained through ES
34        unsafe { self.raw.identity.as_os_str() }
35    }
36
37    /// The identity type of the application string (Bundle ID, path, etc).
38    #[inline(always)]
39    pub fn identity_type(&self) -> es_tcc_identity_type_t {
40        self.raw.identity_type
41    }
42
43    /// The type of TCC modification event (Grant/Revoke etc)
44    #[inline(always)]
45    pub fn update_type(&self) -> es_tcc_event_type_t {
46        self.raw.update_type
47    }
48
49    /// Audit token of the instigator of the modification.
50    #[inline(always)]
51    pub fn instigator_token(&self) -> AuditToken {
52        AuditToken(self.raw.instigator_token)
53    }
54
55    /// (Optional) The process information for the instigator.
56    #[inline(always)]
57    pub fn instigator(&self) -> Option<Process<'a>> {
58        // Safety: 'a tied to self, object obtained through ES
59        let process = unsafe { self.raw.instigator()? };
60        Some(Process::new(process, self.version))
61    }
62
63    /// (Optional) Audit token of the responsible process for the modification.
64    #[inline(always)]
65    pub fn responsible_token(&self) -> Option<AuditToken> {
66        let token = unsafe { self.raw.responsible_token()? };
67        Some(AuditToken(*token))
68    }
69
70    /// (Optional) The process information for the responsible process.
71    #[inline(always)]
72    pub fn responsible(&self) -> Option<Process<'a>> {
73        // Safety: 'a tied to self, object obtained through ES
74        let process = unsafe { self.raw.responsible()? };
75        Some(Process::new(process, self.version))
76    }
77
78    /// The resulting TCC permission of the operation/modification.
79    #[inline(always)]
80    pub fn right(&self) -> es_tcc_authorization_right_t {
81        self.raw.right
82    }
83
84    /// The reason the TCC permissions were updated.
85    #[inline(always)]
86    pub fn reason(&self) -> es_tcc_authorization_reason_t {
87        self.raw.reason
88    }
89}
90
91// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
92unsafe impl Send for EventTccModify<'_> {}
93// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
94unsafe impl Sync for EventTccModify<'_> {}
95
96impl_debug_eq_hash_with_functions!(EventTccModify<'a>; service, identity, identity_type, update_type, instigator_token, instigator, responsible_token, responsible, right, reason);