objc2_security/
lib.rs

1//! # Bindings to the `Security` framework
2//!
3//! See [Apple's docs][apple-doc] and [the general docs on framework crates][framework-crates] for more information.
4//!
5//! [apple-doc]: https://developer.apple.com/documentation/security/
6//! [framework-crates]: https://docs.rs/objc2/latest/objc2/topics/about_generated/index.html
7#![no_std]
8#![cfg_attr(feature = "unstable-darwin-objc", feature(darwin_objc))]
9#![cfg_attr(docsrs, feature(doc_cfg))]
10// Update in Cargo.toml as well.
11#![doc(html_root_url = "https://docs.rs/objc2-security/0.3.2")]
12
13#[cfg(feature = "alloc")]
14extern crate alloc;
15
16#[cfg(feature = "std")]
17extern crate std;
18
19mod generated;
20#[allow(unused_imports, unreachable_pub)]
21pub use self::generated::*;
22
23// Manual fixes.
24#[cfg(all(feature = "libc", feature = "Authorization"))]
25mod authorization;
26#[cfg(feature = "CipherSuite")]
27mod cipher_suite;
28#[cfg(feature = "cssmapple")]
29mod cssmapple;
30#[cfg(all(feature = "libc", feature = "Authorization"))]
31#[allow(unused_imports, unreachable_pub)]
32pub use self::authorization::*;
33#[cfg(feature = "CipherSuite")]
34pub use self::cipher_suite::*;
35#[cfg(feature = "cssmapple")]
36#[allow(unused_imports, unreachable_pub)]
37pub use self::cssmapple::*;
38
39#[cfg(all(feature = "cssmtype", feature = "cssmconfig", feature = "objc2"))]
40use objc2::encode::{Encode, Encoding, RefEncode};
41
42// MacTypes.h
43#[allow(dead_code)]
44pub(crate) type Boolean = u8; // unsigned char
45#[allow(dead_code)]
46pub(crate) type FourCharCode = u32;
47#[allow(dead_code)]
48pub(crate) type OSType = FourCharCode;
49#[allow(dead_code)]
50pub(crate) type OSStatus = i32;
51
52// Fixes
53#[allow(non_camel_case_types, dead_code)]
54pub(crate) type kr_policy_list_item = core::ffi::c_void;
55
56#[allow(non_camel_case_types)]
57#[cfg(feature = "cssmtype")]
58pub type CSSM_STRING = [core::ffi::c_char; 68];
59
60#[allow(non_camel_case_types)]
61#[allow(non_snake_case)]
62#[allow(deprecated)]
63#[cfg(all(
64    feature = "cssmtype",
65    feature = "SecAsn1Types",
66    feature = "cssmconfig",
67    feature = "objc2"
68))]
69#[derive(Copy, Clone)]
70#[repr(C)]
71pub union cssm_list_element_Element {
72    pub Sublist: CSSM_LIST,
73    pub Word: SecAsn1Item,
74}
75
76#[allow(deprecated)]
77#[cfg(all(
78    feature = "cssmtype",
79    feature = "SecAsn1Types",
80    feature = "cssmconfig",
81    feature = "objc2"
82))]
83unsafe impl Encode for cssm_list_element_Element {
84    const ENCODING: Encoding =
85        Encoding::Union("?", &[<CSSM_LIST>::ENCODING, <SecAsn1Item>::ENCODING]);
86}
87
88#[allow(deprecated)]
89#[cfg(all(
90    feature = "cssmtype",
91    feature = "SecAsn1Types",
92    feature = "cssmconfig",
93    feature = "objc2"
94))]
95unsafe impl RefEncode for cssm_list_element_Element {
96    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
97}
98
99#[allow(non_camel_case_types)]
100#[allow(non_snake_case)]
101#[cfg(all(feature = "cssmtype", feature = "SecAsn1Types", feature = "cssmconfig"))]
102#[derive(Copy, Clone)]
103#[repr(C)]
104pub struct cssm_list_element {
105    pub NextElement: *mut cssm_list_element,
106    pub WordID: CSSM_WORDID_TYPE,
107    pub ElementType: CSSM_LIST_ELEMENT_TYPE,
108    pub Element: cssm_list_element_Element,
109}
110
111#[cfg(all(
112    feature = "cssmtype",
113    feature = "SecAsn1Types",
114    feature = "cssmconfig",
115    feature = "objc2"
116))]
117unsafe impl Encode for cssm_list_element {
118    // Empty to avoid constant cycle
119    const ENCODING: Encoding = Encoding::Struct("cssm_list_element", &[]);
120}
121
122#[cfg(all(
123    feature = "cssmtype",
124    feature = "SecAsn1Types",
125    feature = "cssmconfig",
126    feature = "objc2"
127))]
128unsafe impl RefEncode for cssm_list_element {
129    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
130}
131
132// Used by `SecAuthenticationType` for endianness-dependent constants.
133#[cfg(feature = "SecKeychain")]
134#[allow(non_snake_case)]
135macro_rules! AUTH_TYPE_FIX_ {
136    ($code:expr) => {
137        $crate::FourCharCode::from_be($code)
138    };
139}
140#[cfg(feature = "SecKeychain")]
141pub(crate) use AUTH_TYPE_FIX_;