endpoint_sec/event/
event_authentication.rs1use std::ffi::OsStr;
4
5use endpoint_sec_sys::{
6 es_authentication_type_t, es_auto_unlock_type_t, es_event_authentication_auto_unlock_t,
7 es_event_authentication_od_t, es_event_authentication_t, es_event_authentication_t_anon0,
8 es_event_authentication_token_t, es_event_authentication_touchid_t, es_touchid_mode_t, uid_t,
9};
10
11use crate::Process;
12
13#[doc(alias = "es_event_authentication_t")]
15pub struct EventAuthentication<'a> {
16 pub(crate) raw: &'a es_event_authentication_t,
18 pub(crate) version: u32,
20}
21
22impl<'a> EventAuthentication<'a> {
23 #[inline(always)]
25 pub fn success(&self) -> bool {
26 self.raw.success
27 }
28
29 #[inline(always)]
31 pub fn type_(&self) -> es_authentication_type_t {
32 self.raw.type_
33 }
34
35 #[inline(always)]
37 pub fn raw_data(&self) -> &'a es_event_authentication_t_anon0 {
38 &self.raw.data
39 }
40
41 #[inline(always)]
43 pub fn data(&self) -> Option<AuthenticationData<'a>> {
44 let res = match self.type_() {
45 es_authentication_type_t::ES_AUTHENTICATION_TYPE_OD => AuthenticationData::Od(EventAuthenticationOd {
46 raw: unsafe { self.raw_data().od.as_opt()? },
48 version: self.version,
49 }),
50 es_authentication_type_t::ES_AUTHENTICATION_TYPE_TOUCHID => {
51 AuthenticationData::TouchId(EventAuthenticationTouchId {
52 raw: unsafe { self.raw_data().touchid.as_opt()? },
54 version: self.version,
55 success: self.success(),
56 })
57 },
58 es_authentication_type_t::ES_AUTHENTICATION_TYPE_TOKEN => {
59 AuthenticationData::Token(EventAuthenticationToken {
60 raw: unsafe { self.raw_data().token.as_opt()? },
62 version: self.version,
63 })
64 },
65 es_authentication_type_t::ES_AUTHENTICATION_TYPE_AUTO_UNLOCK => {
66 AuthenticationData::AutoUnlock(EventAuthenticationAutoUnlock {
67 raw: unsafe { self.raw_data().auto_unlock.as_opt()? },
69 })
70 },
71 _ => return None,
72 };
73 Some(res)
74 }
75}
76
77unsafe impl Send for EventAuthentication<'_> {}
79unsafe impl Sync for EventAuthentication<'_> {}
81
82impl_debug_eq_hash_with_functions!(EventAuthentication<'a>; success, type_, data);
83
84#[doc(alias = "es_event_authentication_t_anon0")]
86#[doc(alias = "es_authentication_type_t")]
87#[derive(Debug, PartialEq, Eq, Hash)]
88pub enum AuthenticationData<'a> {
89 Od(EventAuthenticationOd<'a>),
91 TouchId(EventAuthenticationTouchId<'a>),
93 Token(EventAuthenticationToken<'a>),
95 AutoUnlock(EventAuthenticationAutoUnlock<'a>),
97}
98
99#[doc(alias = "es_event_authentication_od_t")]
101pub struct EventAuthenticationOd<'a> {
102 raw: &'a es_event_authentication_od_t,
104 version: u32,
106}
107
108impl<'a> EventAuthenticationOd<'a> {
109 #[inline(always)]
111 pub fn instigator(&self) -> Process<'a> {
112 Process::new(
113 unsafe { self.raw.instigator.as_ref() },
115 self.version,
116 )
117 }
118
119 #[inline(always)]
122 pub fn record_type(&self) -> &'a OsStr {
123 unsafe { self.raw.record_type.as_os_str() }
125 }
126
127 #[inline(always)]
130 pub fn record_name(&self) -> &'a OsStr {
131 unsafe { self.raw.record_name.as_os_str() }
133 }
134
135 #[inline(always)]
138 pub fn node_name(&self) -> &'a OsStr {
139 unsafe { self.raw.node_name.as_os_str() }
141 }
142
143 #[inline(always)]
146 pub fn db_path(&self) -> &'a OsStr {
147 unsafe { self.raw.db_path.as_os_str() }
149 }
150}
151
152unsafe impl Send for EventAuthenticationOd<'_> {}
154
155impl_debug_eq_hash_with_functions!(EventAuthenticationOd<'a>; instigator, record_name, node_name, db_path);
156
157#[doc(alias = "es_event_authentication_touchid_t")]
159pub struct EventAuthenticationTouchId<'a> {
160 raw: &'a es_event_authentication_touchid_t,
162 version: u32,
164 success: bool,
166}
167
168impl<'a> EventAuthenticationTouchId<'a> {
169 #[inline(always)]
171 pub fn instigator(&self) -> Process<'a> {
172 Process::new(
173 unsafe { self.raw.instigator.as_ref() },
175 self.version,
176 )
177 }
178
179 #[inline(always)]
181 pub fn touchid_mode(&self) -> es_touchid_mode_t {
182 self.raw.touchid_mode
183 }
184
185 #[inline(always)]
187 pub fn has_uid(&self) -> bool {
188 self.raw.has_uid
189 }
190
191 #[inline(always)]
193 pub fn uid(&self) -> Option<uid_t> {
194 match (self.has_uid(), self.success, self.touchid_mode()) {
195 (true, true, es_touchid_mode_t::ES_TOUCHID_MODE_VERIFICATION) => unsafe { Some(self.raw.anon0.uid) },
197 _ => None,
198 }
199 }
200}
201
202unsafe impl Send for EventAuthenticationTouchId<'_> {}
204
205impl_debug_eq_hash_with_functions!(EventAuthenticationTouchId<'a>; instigator, touchid_mode, has_uid, uid);
206
207#[doc(alias = "es_event_authentication_token_t")]
209pub struct EventAuthenticationToken<'a> {
210 raw: &'a es_event_authentication_token_t,
212 version: u32,
214}
215
216impl<'a> EventAuthenticationToken<'a> {
217 #[inline(always)]
219 pub fn instigator(&self) -> Process<'a> {
220 Process::new(
221 unsafe { self.raw.instigator.as_ref() },
223 self.version,
224 )
225 }
226
227 #[inline(always)]
229 pub fn pubkey_hash(&self) -> &'a OsStr {
230 unsafe { self.raw.pubkey_hash.as_os_str() }
232 }
233
234 #[inline(always)]
236 pub fn token_id(&self) -> &'a OsStr {
237 unsafe { self.raw.token_id.as_os_str() }
239 }
240
241 #[inline(always)]
244 pub fn kerberos_principal(&self) -> &'a OsStr {
245 unsafe { self.raw.kerberos_principal.as_os_str() }
247 }
248}
249
250unsafe impl Send for EventAuthenticationToken<'_> {}
252
253impl_debug_eq_hash_with_functions!(EventAuthenticationToken<'a>; instigator, pubkey_hash, token_id, kerberos_principal);
254
255#[doc(alias = "es_event_authentication_auto_unlock_t")]
257pub struct EventAuthenticationAutoUnlock<'a> {
258 raw: &'a es_event_authentication_auto_unlock_t,
260}
261
262impl<'a> EventAuthenticationAutoUnlock<'a> {
263 #[inline(always)]
265 pub fn username(&self) -> &'a OsStr {
266 unsafe { self.raw.username.as_os_str() }
268 }
269
270 #[inline(always)]
272 pub fn type_(&self) -> es_auto_unlock_type_t {
273 self.raw.type_
274 }
275}
276
277unsafe impl Send for EventAuthenticationAutoUnlock<'_> {}
279
280impl_debug_eq_hash_with_functions!(EventAuthenticationAutoUnlock<'a>; username, type_);