1#![cfg(target_os = "macos")]
21#![cfg_attr(docsrs, feature(doc_cfg))]
22#![allow(clippy::bool_comparison)]
23#![warn(
24 missing_docs,
25 unused_crate_dependencies,
26 clippy::missing_safety_doc,
27 unreachable_pub,
28 clippy::missing_docs_in_private_items,
29 rustdoc::bare_urls,
30 rustdoc::broken_intra_doc_links
31)]
32
33pub use endpoint_sec_sys as sys;
35#[cfg(test)]
36use trybuild as _;
37
38macro_rules! impl_debug_eq_hash_with_functions {
46 ($ty:ident$(<$lt: lifetime>)? $(with $version:ident)?; $($(#[$fmeta: meta])? $fname:ident),* $(,)?) => {
47 impl $(<$lt>)? ::core::fmt::Debug for $ty $(<$lt>)? {
48 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
49 let mut d = f.debug_struct(::core::stringify!($ty));
50 $( d.field("version", &self.$version); )?
51 $( $(#[$fmeta])? d.field(::core::stringify!($fname), &self.$fname()); )*
52 d.finish()
53 }
54 }
55
56 impl $(<$lt>)? ::core::cmp::PartialEq for $ty $(<$lt>)? {
57 #[allow(unused_variables)]
58 fn eq(&self, other: &Self) -> bool {
59 $( if ::core::cmp::PartialEq::ne(&self.$version, &other.$version) { return false } )?
60 $( $(#[$fmeta])? if ::core::cmp::PartialEq::ne(&self.$fname(), &other.$fname()) { return false; } )*
61 true
62 }
63 }
64
65 impl $(<$lt>)? ::core::cmp::Eq for $ty $(<$lt>)? {}
66
67 impl $(<$lt>)? ::core::hash::Hash for $ty $(<$lt>)? {
68 #[allow(unused_variables)]
69 fn hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
70 $( ::core::hash::Hash::hash(&self.$version, state); )?
71 $( $(#[$fmeta])? ::core::hash::Hash::hash(&self.$fname(), state); )*
72 }
73 }
74
75 };
76}
77
78macro_rules! versioned_call {
80 (if cfg!($cfg: meta) && version >= ($major:literal, $minor:literal, $patch:literal) { $($if_tt:tt)* } $(else { $($else_tt:tt)* })?) => {
82 if ::std::cfg!($cfg) && $crate::version::is_version_or_more($major, $minor, $patch) {
83 #[cfg($cfg)]
84 { $($if_tt)* }
85 #[cfg(not($cfg))]
86 unsafe { ::std::hint::unreachable_unchecked() }
88 } $( else {
89 $($else_tt)*
90 } )?
91 };
92}
93
94#[cfg(feature = "macos_10_15_1")]
96mod acl;
97mod action;
98mod audit;
99mod client;
100mod event;
101mod message;
102mod mute;
103mod utils;
105
106#[cfg(feature = "macos_10_15_1")]
107pub use acl::*;
108pub use action::*;
109pub use audit::*;
110pub use client::*;
111pub use event::*;
112pub use message::*;
113pub use mute::*;
114
115pub mod version {
118 use std::sync::atomic::{AtomicU64, Ordering};
119
120 static MAJOR: AtomicU64 = AtomicU64::new(10);
122 static MINOR: AtomicU64 = AtomicU64::new(15);
124 static PATCH: AtomicU64 = AtomicU64::new(0);
126
127 pub fn set_runtime_version(major: u64, minor: u64, patch: u64) {
139 if major < 10 || (major == 10 && minor < 15) {
140 panic!("Endpoint Security cannot run on versions inferiors to 10.15.0");
141 }
142
143 MAJOR.store(major, Ordering::Release);
144 MINOR.store(minor, Ordering::Release);
145 PATCH.store(patch, Ordering::Release);
146 }
147
148 pub fn is_version_or_more(major: u64, minor: u64, patch: u64) -> bool {
151 let current_major = MAJOR.load(Ordering::Acquire);
152 let current_minor = MINOR.load(Ordering::Acquire);
153 let current_patch = PATCH.load(Ordering::Acquire);
154
155 (current_major, current_minor, current_patch) >= (major, minor, patch)
156 }
157
158 #[cfg(test)]
159 mod tests {
160 use super::*;
161
162 #[test]
163 #[should_panic(expected = "Endpoint Security cannot run on versions inferiors to 10.15.0")]
164 fn test_cannot_set_version_major_under_10() {
165 set_runtime_version(9, 16, 2);
166 }
167
168 #[test]
169 #[should_panic(expected = "Endpoint Security cannot run on versions inferiors to 10.15.0")]
170 fn test_cannot_set_version_minor_under_10_15() {
171 set_runtime_version(10, 14, 0);
172 }
173
174 #[test]
175 fn test_is_version_or_more_with_set_runtime() {
176 set_runtime_version(10, 15, 0);
177
178 assert!(is_version_or_more(10, 14, 99));
179 assert!(is_version_or_more(9, 15, 0));
180 assert!(is_version_or_more(9, 14, 1));
181 assert!(is_version_or_more(10, 15, 0));
182
183 assert!(!is_version_or_more(12, 3, 1));
184 assert!(!is_version_or_more(13, 3, 2));
185 assert!(!is_version_or_more(14, 5, 4));
186 assert!(!is_version_or_more(15, 0, 0));
187
188 set_runtime_version(13, 3, 2);
189
190 assert!(is_version_or_more(12, 3, 1));
191 assert!(is_version_or_more(13, 3, 2));
192 assert!(!is_version_or_more(14, 5, 4));
193 assert!(!is_version_or_more(15, 0, 0));
194 }
195 }
196}