objc2_security/generated/
AuthorizationPlugin.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10
11use crate::*;
12
13/// Auxiliary data is passed between the engine and the mechanism as AuthorizationValues
14///
15/// See also [Apple's documentation](https://developer.apple.com/documentation/security/authorizationvalue?language=objc)
16#[repr(C)]
17#[derive(Clone, Copy, Debug, PartialEq)]
18pub struct AuthorizationValue {
19    pub length: usize,
20    pub data: *mut c_void,
21}
22
23#[cfg(feature = "objc2")]
24unsafe impl Encode for AuthorizationValue {
25    const ENCODING: Encoding = Encoding::Struct(
26        "AuthorizationValue",
27        &[<usize>::ENCODING, <*mut c_void>::ENCODING],
28    );
29}
30
31#[cfg(feature = "objc2")]
32unsafe impl RefEncode for AuthorizationValue {
33    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
34}
35
36/// A vector of AuthorizationValues.  Used to communicate arguments passed from the
37/// configuration file
38/// <code>
39/// authorization(5)
40/// </code>
41/// .
42///
43/// See also [Apple's documentation](https://developer.apple.com/documentation/security/authorizationvaluevector?language=objc)
44#[repr(C)]
45#[derive(Clone, Copy, Debug, PartialEq)]
46pub struct AuthorizationValueVector {
47    pub count: u32,
48    pub values: NonNull<AuthorizationValue>,
49}
50
51#[cfg(feature = "objc2")]
52unsafe impl Encode for AuthorizationValueVector {
53    const ENCODING: Encoding = Encoding::Struct(
54        "AuthorizationValueVector",
55        &[<u32>::ENCODING, <NonNull<AuthorizationValue>>::ENCODING],
56    );
57}
58
59#[cfg(feature = "objc2")]
60unsafe impl RefEncode for AuthorizationValueVector {
61    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
62}
63
64/// Data produced as context during the authorization evaluation is tagged.
65/// If data is set to be extractable (kAuthorizationContextFlagExtractable), it will be possible for the client of authorization to obtain the value of this attribute using AuthorizationCopyInfo().
66/// If data is marked as volatile (kAuthorizationContextFlagVolatile), this value will not be remembered in the AuthorizationRef.
67/// Sticky data (kAuthorizationContextFlagSticky) persists through a failed or interrupted evaluation. It can be used to propagate an error condition from a downstream plugin to an upstream one. It is not remembered in the AuthorizationRef.
68///
69/// See also [Apple's documentation](https://developer.apple.com/documentation/security/authorizationcontextflags?language=objc)
70// NS_OPTIONS
71#[repr(transparent)]
72#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
73pub struct AuthorizationContextFlags(pub u32);
74bitflags::bitflags! {
75    impl AuthorizationContextFlags: u32 {
76        #[doc(alias = "kAuthorizationContextFlagExtractable")]
77        const Extractable = 1<<0;
78        #[doc(alias = "kAuthorizationContextFlagVolatile")]
79        const Volatile = 1<<1;
80        #[doc(alias = "kAuthorizationContextFlagSticky")]
81        const Sticky = 1<<2;
82    }
83}
84
85#[cfg(feature = "objc2")]
86unsafe impl Encode for AuthorizationContextFlags {
87    const ENCODING: Encoding = u32::ENCODING;
88}
89
90#[cfg(feature = "objc2")]
91unsafe impl RefEncode for AuthorizationContextFlags {
92    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
93}
94
95/// The mechanism id specified in the configuration is passed to the plugin to create the appropriate mechanism.
96///
97/// See also [Apple's documentation](https://developer.apple.com/documentation/security/authorizationmechanismid?language=objc)
98#[cfg(feature = "Authorization")]
99pub type AuthorizationMechanismId = AuthorizationString;
100
101/// Not used by plugin writers.  Loaded plugins are identified by their name.
102///
103/// See also [Apple's documentation](https://developer.apple.com/documentation/security/authorizationpluginid?language=objc)
104#[cfg(feature = "Authorization")]
105pub type AuthorizationPluginId = AuthorizationString;
106
107/// Handle passed back by the plugin writer when creating a plugin.  Any pluginhost will only instantiate one instance.  The handle is used when creating mechanisms.
108///
109/// See also [Apple's documentation](https://developer.apple.com/documentation/security/authorizationpluginref?language=objc)
110pub type AuthorizationPluginRef = *mut c_void;
111
112/// Handle passed back by the plugin writer when creating an an instance of a mechanism in a plugin.  One instance will be created for any authorization.
113///
114/// See also [Apple's documentation](https://developer.apple.com/documentation/security/authorizationmechanismref?language=objc)
115pub type AuthorizationMechanismRef = *mut c_void;
116
117/// [Apple's documentation](https://developer.apple.com/documentation/security/__opaqueauthorizationengine?language=objc)
118#[repr(C)]
119#[derive(Debug)]
120pub struct __OpaqueAuthorizationEngine {
121    inner: [u8; 0],
122    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
123}
124
125#[cfg(feature = "objc2")]
126unsafe impl RefEncode for __OpaqueAuthorizationEngine {
127    const ENCODING_REF: Encoding =
128        Encoding::Pointer(&Encoding::Struct("__OpaqueAuthorizationEngine", &[]));
129}
130
131/// Handle passed from the engine to an instance of a mechanism in a plugin (corresponds to a particular AuthorizationMechanismRef).
132///
133/// See also [Apple's documentation](https://developer.apple.com/documentation/security/authorizationengineref?language=objc)
134pub type AuthorizationEngineRef = *mut __OpaqueAuthorizationEngine;
135
136/// A unique value for an AuthorizationSession being evaluated, provided by the authorization engine.
137/// A session is represented by a top level call to an Authorization API.
138///
139/// See also [Apple's documentation](https://developer.apple.com/documentation/security/authorizationsessionid?language=objc)
140pub type AuthorizationSessionId = *mut c_void;
141
142/// Possible values for SetResult() in AuthorizationCallbacks.
143///
144/// See also [Apple's documentation](https://developer.apple.com/documentation/security/authorizationresult?language=objc)
145// NS_CLOSED_ENUM
146#[repr(u32)]
147#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
148pub enum AuthorizationResult {
149    #[doc(alias = "kAuthorizationResultAllow")]
150    Allow = 0,
151    #[doc(alias = "kAuthorizationResultDeny")]
152    Deny = 1,
153    #[doc(alias = "kAuthorizationResultUndefined")]
154    Undefined = 2,
155    #[doc(alias = "kAuthorizationResultUserCanceled")]
156    UserCanceled = 3,
157}
158
159#[cfg(feature = "objc2")]
160unsafe impl Encode for AuthorizationResult {
161    const ENCODING: Encoding = u32::ENCODING;
162}
163
164#[cfg(feature = "objc2")]
165unsafe impl RefEncode for AuthorizationResult {
166    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
167}
168
169/// [Apple's documentation](https://developer.apple.com/documentation/security/kauthorizationplugininterfaceversion?language=objc)
170pub const kAuthorizationPluginInterfaceVersion: c_uint = 0;
171
172/// [Apple's documentation](https://developer.apple.com/documentation/security/kauthorizationcallbacksversion?language=objc)
173pub const kAuthorizationCallbacksVersion: c_uint = 4;
174
175/// Callback API provided by the AuthorizationEngine.
176///
177/// Field: version      Engine callback version.
178/// Field: SetResult    Set a result after a call to AuthorizationSessionInvoke.
179/// Field: RequestInterrupt Request authorization engine to interrupt all mechamisms invoked after this mechamism has called SessionSetResult and then call AuthorizationSessionInvoke again.
180/// Field: DidDeactivate    Respond to the Deactivate request.
181/// Field: GetContextValue  Read value from context.  AuthorizationValue does not own data.
182/// Field: SetContextValue  Write value to context.  AuthorizationValue and data are copied.
183/// Field: GetHintValue     Read value from hints. AuthorizationValue does not own data.
184/// Field: SetHintValue     Write value to hints.  AuthorizationValue and data are copied.
185/// Field: GetArguments     Read arguments passed.  AuthorizationValueVector does not own data.
186/// Field: GetSessionId     Read SessionId.
187/// Field: GetLAContext     Returns LAContext which will have LACredentialCTKPIN credential set if PIN is available otherwise context without credentials is returned. LAContext can be used for operations with Tokens which would normally require PIN. Caller owns returned context and is responsible for release.
188/// Field: GetTokenIdentities   Returns array of identities. Caller owns returned array and is reponsible for release.
189/// Field: GetTKTokenWatcher    Returns TKTokenWatcher object. Caller owns returned context and is responsible for release.
190/// Field: RemoveContextValue   Removes value from context.
191/// Field: RemoveHintValue      Removes value from hints.
192///
193/// See also [Apple's documentation](https://developer.apple.com/documentation/security/authorizationcallbacks?language=objc)
194#[cfg(feature = "Authorization")]
195#[repr(C)]
196#[allow(unpredictable_function_pointer_comparisons)]
197#[derive(Clone, Copy, Debug, PartialEq)]
198pub struct AuthorizationCallbacks {
199    pub version: u32,
200    pub SetResult:
201        unsafe extern "C-unwind" fn(AuthorizationEngineRef, AuthorizationResult) -> OSStatus,
202    pub RequestInterrupt: unsafe extern "C-unwind" fn(AuthorizationEngineRef) -> OSStatus,
203    pub DidDeactivate: unsafe extern "C-unwind" fn(AuthorizationEngineRef) -> OSStatus,
204    pub GetContextValue: unsafe extern "C-unwind" fn(
205        AuthorizationEngineRef,
206        AuthorizationString,
207        *mut AuthorizationContextFlags,
208        *mut *const AuthorizationValue,
209    ) -> OSStatus,
210    pub SetContextValue: unsafe extern "C-unwind" fn(
211        AuthorizationEngineRef,
212        AuthorizationString,
213        AuthorizationContextFlags,
214        NonNull<AuthorizationValue>,
215    ) -> OSStatus,
216    pub GetHintValue: unsafe extern "C-unwind" fn(
217        AuthorizationEngineRef,
218        AuthorizationString,
219        *mut *const AuthorizationValue,
220    ) -> OSStatus,
221    pub SetHintValue: unsafe extern "C-unwind" fn(
222        AuthorizationEngineRef,
223        AuthorizationString,
224        NonNull<AuthorizationValue>,
225    ) -> OSStatus,
226    pub GetArguments: unsafe extern "C-unwind" fn(
227        AuthorizationEngineRef,
228        NonNull<*const AuthorizationValueVector>,
229    ) -> OSStatus,
230    pub GetSessionId: unsafe extern "C-unwind" fn(
231        AuthorizationEngineRef,
232        *mut AuthorizationSessionId,
233    ) -> OSStatus,
234    pub GetImmutableHintValue: unsafe extern "C-unwind" fn(
235        AuthorizationEngineRef,
236        AuthorizationString,
237        *mut *const AuthorizationValue,
238    ) -> OSStatus,
239    pub GetLAContext:
240        unsafe extern "C-unwind" fn(AuthorizationEngineRef, *mut *const CFType) -> OSStatus,
241    pub GetTokenIdentities: unsafe extern "C-unwind" fn(
242        AuthorizationEngineRef,
243        NonNull<CFType>,
244        *mut *const CFArray,
245    ) -> OSStatus,
246    pub GetTKTokenWatcher:
247        unsafe extern "C-unwind" fn(AuthorizationEngineRef, *mut *const CFType) -> OSStatus,
248    pub RemoveHintValue:
249        unsafe extern "C-unwind" fn(AuthorizationEngineRef, AuthorizationString) -> OSStatus,
250    pub RemoveContextValue:
251        unsafe extern "C-unwind" fn(AuthorizationEngineRef, AuthorizationString) -> OSStatus,
252}
253
254#[cfg(all(feature = "Authorization", feature = "objc2"))]
255unsafe impl Encode for AuthorizationCallbacks {
256    const ENCODING: Encoding = Encoding::Struct("AuthorizationCallbacks", &[
257        <u32>::ENCODING,
258        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,AuthorizationResult,) -> OSStatus>::ENCODING,
259        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,) -> OSStatus>::ENCODING,
260        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,) -> OSStatus>::ENCODING,
261        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,AuthorizationString,*mut AuthorizationContextFlags,*mut *const AuthorizationValue,) -> OSStatus>::ENCODING,
262        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,AuthorizationString,AuthorizationContextFlags,NonNull<AuthorizationValue>,) -> OSStatus>::ENCODING,
263        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,AuthorizationString,*mut *const AuthorizationValue,) -> OSStatus>::ENCODING,
264        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,AuthorizationString,NonNull<AuthorizationValue>,) -> OSStatus>::ENCODING,
265        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,NonNull<*const AuthorizationValueVector>,) -> OSStatus>::ENCODING,
266        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,*mut AuthorizationSessionId,) -> OSStatus>::ENCODING,
267        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,AuthorizationString,*mut *const AuthorizationValue,) -> OSStatus>::ENCODING,
268        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,*mut *const CFType,) -> OSStatus>::ENCODING,
269        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,NonNull<CFType>,*mut *const CFArray,) -> OSStatus>::ENCODING,
270        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,*mut *const CFType,) -> OSStatus>::ENCODING,
271        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,AuthorizationString,) -> OSStatus>::ENCODING,
272        <unsafe extern "C-unwind" fn(AuthorizationEngineRef,AuthorizationString,) -> OSStatus>::ENCODING,
273    ]);
274}
275
276#[cfg(all(feature = "Authorization", feature = "objc2"))]
277unsafe impl RefEncode for AuthorizationCallbacks {
278    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
279}
280
281/// Interface that must be implemented by each plugin.
282///
283/// Field: version  Must be set to kAuthorizationPluginInterfaceVersion
284/// Field: PluginDestroy    Plugin should clean up and release any resources it is holding.
285/// Field: MechanismCreate  The plugin should create a mechanism named mechanismId.  The mechanism needs to use the AuthorizationEngineRef for the callbacks and pass back a   AuthorizationMechanismRef for itself.  MechanismDestroy will be called when it is no longer needed.
286/// Field: MechanismInvoke  Invoke an instance of a mechanism.  It should call SetResult during or after returning from this function.
287/// Field: MechanismDeactivate  Mechanism should respond with a DidDeactivate as soon as possible
288/// Field: MechanismDestroy Mechanism should clean up and release any resources it is holding
289///
290/// See also [Apple's documentation](https://developer.apple.com/documentation/security/authorizationplugininterface?language=objc)
291#[cfg(feature = "Authorization")]
292#[repr(C)]
293#[allow(unpredictable_function_pointer_comparisons)]
294#[derive(Clone, Copy, Debug, PartialEq)]
295pub struct AuthorizationPluginInterface {
296    pub version: u32,
297    pub PluginDestroy: unsafe extern "C-unwind" fn(AuthorizationPluginRef) -> OSStatus,
298    pub MechanismCreate: unsafe extern "C-unwind" fn(
299        AuthorizationPluginRef,
300        AuthorizationEngineRef,
301        AuthorizationMechanismId,
302        NonNull<AuthorizationMechanismRef>,
303    ) -> OSStatus,
304    pub MechanismInvoke: unsafe extern "C-unwind" fn(AuthorizationMechanismRef) -> OSStatus,
305    pub MechanismDeactivate: unsafe extern "C-unwind" fn(AuthorizationMechanismRef) -> OSStatus,
306    pub MechanismDestroy: unsafe extern "C-unwind" fn(AuthorizationMechanismRef) -> OSStatus,
307}
308
309#[cfg(all(feature = "Authorization", feature = "objc2"))]
310unsafe impl Encode for AuthorizationPluginInterface {
311    const ENCODING: Encoding = Encoding::Struct(
312        "AuthorizationPluginInterface",
313        &[
314            <u32>::ENCODING,
315            <unsafe extern "C-unwind" fn(AuthorizationPluginRef) -> OSStatus>::ENCODING,
316            <unsafe extern "C-unwind" fn(
317                AuthorizationPluginRef,
318                AuthorizationEngineRef,
319                AuthorizationMechanismId,
320                NonNull<AuthorizationMechanismRef>,
321            ) -> OSStatus>::ENCODING,
322            <unsafe extern "C-unwind" fn(AuthorizationMechanismRef) -> OSStatus>::ENCODING,
323            <unsafe extern "C-unwind" fn(AuthorizationMechanismRef) -> OSStatus>::ENCODING,
324            <unsafe extern "C-unwind" fn(AuthorizationMechanismRef) -> OSStatus>::ENCODING,
325        ],
326    );
327}
328
329#[cfg(all(feature = "Authorization", feature = "objc2"))]
330unsafe impl RefEncode for AuthorizationPluginInterface {
331    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
332}
333
334extern "C-unwind" {
335    /// Initialize a plugin after it gets loaded.  This is the main entry point to a plugin.  This function will only be called once.
336    /// After all Mechanism instances have been destroyed outPluginInterface->PluginDestroy will be called.
337    ///
338    ///
339    /// Parameter `callbacks`: (input) A pointer to an AuthorizationCallbacks which contains the callbacks implemented by the AuthorizationEngine.
340    ///
341    /// Parameter `outPlugin`: (output) On successful completion should contain a valid AuthorizationPluginRef.  This will be passed in to any subsequent calls the engine makes to  outPluginInterface->MechanismCreate and outPluginInterface->PluginDestroy.
342    ///
343    /// Parameter `outPluginInterface`: (output) On successful completion should contain a pointer to a AuthorizationPluginInterface that will stay valid until outPluginInterface->PluginDestroy is called.
344    ///
345    /// # Safety
346    ///
347    /// - `callbacks` must be a valid pointer.
348    /// - `out_plugin` must be a valid pointer.
349    /// - `out_plugin_interface` must be a valid pointer.
350    #[cfg(feature = "Authorization")]
351    pub fn AuthorizationPluginCreate(
352        callbacks: NonNull<AuthorizationCallbacks>,
353        out_plugin: NonNull<AuthorizationPluginRef>,
354        out_plugin_interface: NonNull<*const AuthorizationPluginInterface>,
355    ) -> OSStatus;
356}