#![doc = concat!("[esc]: https://docs.rs/endpoint-sec/", env!("CARGO_PKG_VERSION"), "/endpoint-sec")]
#![cfg(target_os = "macos")]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(
deref_nullptr,
non_camel_case_types,
non_snake_case,
clippy::bool_comparison,
clippy::missing_safety_doc,
clippy::undocumented_unsafe_blocks
)]
#![warn(
unused_crate_dependencies,
unreachable_pub,
rustdoc::bare_urls,
rustdoc::broken_intra_doc_links
)]
use core::{fmt, ptr};
#[repr(transparent)]
pub struct ShouldNotBeNull<T: ?Sized>(*mut T);
impl<T: ?Sized> Clone for ShouldNotBeNull<T> {
#[inline]
fn clone(&self) -> Self {
*self
}
}
impl<T: ?Sized> Copy for ShouldNotBeNull<T> {}
impl<T: ?Sized> ShouldNotBeNull<T> {
#[inline]
pub fn new(p: *mut T) -> Self {
Self(p)
}
#[inline]
pub unsafe fn as_ref<'a>(&self) -> &'a T {
unsafe { self.0.as_ref().expect("Pointer was null when it should not") }
}
#[inline]
pub unsafe fn as_opt<'a>(&self) -> Option<&'a T> {
unsafe { self.0.as_ref() }
}
#[inline]
pub const fn as_ptr(self) -> *const T {
self.0 as *const _
}
}
impl<T: ?Sized> fmt::Debug for ShouldNotBeNull<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Pointer::fmt(&self.as_ptr(), f)
}
}
impl<T: ?Sized> fmt::Pointer for ShouldNotBeNull<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Pointer::fmt(&self.as_ptr(), f)
}
}
impl<T: ?Sized> Eq for ShouldNotBeNull<T> {}
impl<T: ?Sized> PartialEq for ShouldNotBeNull<T> {
#[inline]
fn eq(&self, other: &Self) -> bool {
ptr::eq(self.as_ptr(), other.as_ptr())
}
}
macro_rules! slice_access {
($ty:ty[. $data:ident; . $count:ident]: fn $fn_name:ident() -> $slice_ty:ty) => {
impl $ty {
#[doc = ::core::stringify!($count)]
#[doc = ::core::stringify!($data)]
#[inline]
pub unsafe fn $fn_name(&self) -> &[$slice_ty] {
if self.$count > 0 && self.$data.is_null() == false {
unsafe { ::core::slice::from_raw_parts(self.$data, self.$count) }
} else {
&[]
}
}
}
};
}
macro_rules! ffi_wrap_enum {
(
$(#[$doc_enum:meta])*
$enum_name: ident ($inner_type: ty);
$(
== LAST;
$(#[$doc_last:meta])*
$variant_last: ident,
)?
$(
== MACOS_10_15_0;
$(
$(#[$doc_first:meta])*
$variant_first: ident = $value_first: literal,
)*
--
$(#[$doc_last_first:meta])*
$variant_last_first: ident = $value_last_first: literal,
)?
$(
== #[cfg(feature = $ver_feature_lit:literal)] $ver_ident:tt $ver_str:literal;
$(
$(#[$doc_ver:meta])*
$variant_ver: ident = $value_ver: literal,
)*
--
$(#[$doc_last_ver:meta])*
$variant_last_ver: ident = $value_last_ver: literal,
)*
) => {
$(#[$doc_enum])*
#[repr(transparent)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct $enum_name(pub $inner_type);
$(
/// Variants available from macOS 10.15.0 onwards
impl $enum_name {
$(
$(#[$doc_first])*
pub const $variant_first: $enum_name = $enum_name($value_first);
)*
$(#[$doc_last_first])*
pub const $variant_last_first: $enum_name = $enum_name($value_last_first);
}
)?
$(
#[doc = "Variants available from macOS "]
#[doc = $ver_str]
#[doc = " onwards"]
#[cfg(feature = $ver_feature_lit)]
impl $enum_name {
$(
$(#[$doc_ver])*
pub const $variant_ver: $enum_name = $enum_name($value_ver);
)*
$(#[$doc_last_ver])*
#[doc = "Last value for macOS " ]
#[doc = $ver_str]
pub const $variant_last_ver: $enum_name = $enum_name($value_last_ver);
}
)*
impl $enum_name {
const __COMPUTED_LAST_VARIANT: $enum_name = $enum_name({
const LAST_VALUE: $enum_name = match &[
$($enum_name::$variant_last_first,)?
$(#[cfg(feature = $ver_feature_lit)] $enum_name::$variant_last_ver,)?
] {
[.., last] => *last,
};
LAST_VALUE.0 + 1
});
$(
pub const $variant_last: $enum_name = $enum_name::__COMPUTED_LAST_VARIANT;
)?
}
impl ::core::fmt::Debug for $enum_name {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
match *self {
$($(
Self::$variant_first => ffi_wrap_enum!(DEBUG f, $enum_name::$variant_first($value_first)),
)*)?
$(
Self::$variant_last_first => ffi_wrap_enum!(DEBUG f, $enum_name::$variant_last_first($value_last_first)),
)?
$(
$(
#[cfg(feature = $ver_feature_lit)]
Self::$variant_ver => ffi_wrap_enum!(DEBUG f, $enum_name::$variant_ver($value_ver)),
)*
#[cfg(feature = $ver_feature_lit)]
Self::$variant_last_ver => ffi_wrap_enum!(DEBUG f, $enum_name::$variant_last_ver($value_last_ver)),
)*
$(
Self::$variant_last => ::core::write!(
f, ::core::concat!(::core::stringify!($enum_name), "::", ::core::stringify!($variant_last), "({})"), self.0
),
)?
unknown => ::core::write!(f, ::core::concat!(::core::stringify!($enum_name), "({})"), unknown.0),
}
}
}
};
(DEBUG $f: ident, $enum_name: ident :: $variant_name: ident ($variant_value: literal)) => {
::core::write!($f, ::core::concat!(
::core::stringify!($enum_name), "::", ::core::stringify!($variant_name), "(", $variant_value, ")",
))
}
}
macro_rules! should_not_be_null_fields {
($ty: ty; $($field: ident -> $field_ty: ty),+ $(,)?) => {
impl $ty {
$(
#[inline]
pub unsafe fn $field(&self) -> &$field_ty {
unsafe { $crate::ShouldNotBeNull::as_ref(&self.$field) }
}
)+
}
};
}
macro_rules! null_fields {
($ty: ty; $($field: ident -> $field_ty: ty),+ $(,)?) => {
impl $ty {
$(
#[inline]
pub unsafe fn $field(&self) -> Option<&$field_ty> {
unsafe { self.$field.as_ref() }
}
)+
}
};
}
mod types;
pub use types::*;
mod message;
pub use message::*;
mod client;
pub use client::*;
mod additional;
pub use additional::*;
mod result_wrapping;
pub use result_wrapping::*;