objc2_security_interface/generated/SFAuthorizationPluginView.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_app_kit::*;
7use objc2_foundation::*;
8#[cfg(feature = "objc2-security")]
9use objc2_security::*;
10
11use crate::*;
12
13/// Defines the button types that are used by AuthorizationPlugins.
14///
15/// See also [Apple's documentation](https://developer.apple.com/documentation/securityinterface/sfbuttontype?language=objc)
16#[repr(transparent)]
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
18pub struct SFButtonType(pub c_uint);
19impl SFButtonType {
20 #[doc(alias = "SFButtonTypeCancel")]
21 pub const Cancel: Self = Self(0);
22 #[doc(alias = "SFButtonTypeOK")]
23 pub const OK: Self = Self(1);
24 #[doc(alias = "SFButtonTypeBack")]
25 pub const Back: Self = Self(SFButtonType::Cancel.0);
26 #[doc(alias = "SFButtonTypeLogin")]
27 pub const Login: Self = Self(SFButtonType::OK.0);
28}
29
30unsafe impl Encode for SFButtonType {
31 const ENCODING: Encoding = c_uint::ENCODING;
32}
33
34unsafe impl RefEncode for SFButtonType {
35 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
36}
37
38/// Defines the view types requested by AuthorizationPlugins.
39///
40/// See also [Apple's documentation](https://developer.apple.com/documentation/securityinterface/sfviewtype?language=objc)
41#[repr(transparent)]
42#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
43pub struct SFViewType(pub c_uint);
44impl SFViewType {
45 #[doc(alias = "SFViewTypeIdentityAndCredentials")]
46 pub const IdentityAndCredentials: Self = Self(0);
47 #[doc(alias = "SFViewTypeCredentials")]
48 pub const Credentials: Self = Self(1);
49}
50
51unsafe impl Encode for SFViewType {
52 const ENCODING: Encoding = c_uint::ENCODING;
53}
54
55unsafe impl RefEncode for SFViewType {
56 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
57}
58
59extern_class!(
60 /// SFAuthorizationPluginView is a class that you can use to insert an NSView into AuthorizationPlugin interfaces.
61 ///
62 /// SFAuthorizationPluginView provides AuthorizationPlugin writers with an easy way to provide a user interface for their AuthorizationPlugin without having to duplicate the standard authentication dialog or the login window dialog. This class was designed to be subclassed by the AuthorizationPlugin writer. The following methods were designed to be overridden: buttonPressed:, didActivate, willActivateWithUser:, didDeactivate, firstKeyView, firstResponder, lastKeyView, setEnabled:, and viewForType:. In order to display the user interface, the AuthorizationPlugin should create an instance of your subclass and then call displayView. That will cause the appropriate dialog to be displayed and when credentials are needed, the overridden methods will be called in order to display the NSView provided by the subclass.
63 ///
64 /// See also [Apple's documentation](https://developer.apple.com/documentation/securityinterface/sfauthorizationpluginview?language=objc)
65 #[unsafe(super(NSObject))]
66 #[derive(Debug, PartialEq, Eq, Hash)]
67 pub struct SFAuthorizationPluginView;
68);
69
70extern_conformance!(
71 unsafe impl NSObjectProtocol for SFAuthorizationPluginView {}
72);
73
74impl SFAuthorizationPluginView {
75 extern_methods!(
76 #[cfg(feature = "objc2-security")]
77 /// The initialization method of this class. You must provide the callbacks and engineRef that were provided to the AuthorizationPlugin and AuthorizationMechanismRef.
78 ///
79 /// Parameter `callbacks`: The AuthorizationCallbacks provided to the AuthorizationPlugin.
80 ///
81 /// Parameter `engineRef`: The AuthorizationEngineRef provided to the AuthorizationMechanismRef.
82 #[unsafe(method(initWithCallbacks:andEngineRef:))]
83 #[unsafe(method_family = init)]
84 pub unsafe fn initWithCallbacks_andEngineRef(
85 this: Allocated<Self>,
86 callbacks: *const AuthorizationCallbacks,
87 engine_ref: AuthorizationEngineRef,
88 ) -> Option<Retained<Self>>;
89
90 #[cfg(feature = "objc2-security")]
91 /// An accessor method to the AuthorizationEngineRef provided to the init method. Use this value when calling the functions of the AuthorizationCallbacks when you need to set the result or set a context value.
92 #[unsafe(method(engineRef))]
93 #[unsafe(method_family = none)]
94 pub unsafe fn engineRef(&self) -> AuthorizationEngineRef;
95
96 #[cfg(feature = "objc2-security")]
97 /// An accessor method to the AuthorizationEngineRef provided to the init method. Use this to get the function pointers to SetResult, SetContextValue, etc. See the AuthorizationCallbacks documentation for more details.
98 #[unsafe(method(callbacks))]
99 #[unsafe(method_family = none)]
100 pub unsafe fn callbacks(&self) -> *const AuthorizationCallbacks;
101
102 /// When a user presses a button, this method will be called to inform the SFAuthorizationPluginView of the user's action. By default buttonPressed: will set a result of Deny when the OK or Login buttons are pressed.
103 ///
104 /// If a user has pressed Login or OK button was pressed, the subclass needs to set the context values for the short name of the user so that user attributes can be looked up. Use kAuthorizationEnvironmentUsername as the key. The subclass should also set any additional context values that are needed by the authentication plugin to verify the user's credentials.
105 ///
106 ///
107 /// Parameter `inButtonType`: the type of button that was pressed.
108 #[unsafe(method(buttonPressed:))]
109 #[unsafe(method_family = none)]
110 pub unsafe fn buttonPressed(&self, in_button_type: SFButtonType);
111
112 /// Called by the Apple provided SecurityAgent plugin to get a description of the error that occurred during evaluation. If no error occurred, the method should return nil.
113 ///
114 /// A downstream mechanism that works in cooperation with the SFAuthorizationPluginView can set a context value using the kAuthorizationContextFlagSticky flag to make it available to the SFAuthorizationPluginView in case of an error.
115 #[unsafe(method(lastError))]
116 #[unsafe(method_family = none)]
117 pub unsafe fn lastError(&self) -> Option<Retained<NSError>>;
118
119 /// Called when the user interface was made active by the AuthorizationPlugin.
120 #[unsafe(method(didActivate))]
121 #[unsafe(method_family = none)]
122 pub unsafe fn didActivate(&self);
123
124 /// Called by the Apple provided SecurityAgent plugin before the UI is made active.
125 ///
126 /// Parameter `inUserInformation`: is a dictionary contains the following information:
127 /// kSFAuthorizationPluginViewUserNameKey - an NSString with the selected user's name
128 /// kSFAuthorizationPluginViewUserShortNameKey - an NSString with the selected user's short name
129 ///
130 /// The user name can be used to pre-populate a Text Field.
131 /// NOTE: inUserInformation may be nil.
132 #[unsafe(method(willActivateWithUser:))]
133 #[unsafe(method_family = none)]
134 pub unsafe fn willActivateWithUser(&self, in_user_information: Option<&NSDictionary>);
135
136 /// Called when the user interface is deactivated by the AuthorizationPlugin.
137 #[unsafe(method(didDeactivate))]
138 #[unsafe(method_family = none)]
139 pub unsafe fn didDeactivate(&self);
140
141 /// When called by the AuthorizationPlugin, the subclass should return the first view in the keyboard loop of the NSView. The default value returned is nil.
142 #[unsafe(method(firstKeyView))]
143 #[unsafe(method_family = none)]
144 pub unsafe fn firstKeyView(&self, mtm: MainThreadMarker) -> Option<Retained<NSView>>;
145
146 /// When called by the AuthorizationPlugin, the subclass should return the view that should get the focus for keyboard events. The default value returned is nil.
147 #[unsafe(method(firstResponder))]
148 #[unsafe(method_family = none)]
149 pub unsafe fn firstResponder(&self, mtm: MainThreadMarker)
150 -> Option<Retained<NSResponder>>;
151
152 /// When called by the AuthorizationPlugin, the subclass should return the last view in the keyboard loop for the view. The default value returned is nil.
153 #[unsafe(method(lastKeyView))]
154 #[unsafe(method_family = none)]
155 pub unsafe fn lastKeyView(&self, mtm: MainThreadMarker) -> Option<Retained<NSView>>;
156
157 /// When called by the AuthorizationPlugin, the subclass should call setEnabled: on the controls that are in its view.
158 ///
159 /// Parameter `inEnabled`: the state the controls should be in.
160 #[unsafe(method(setEnabled:))]
161 #[unsafe(method_family = none)]
162 pub unsafe fn setEnabled(&self, in_enabled: bool);
163
164 /// When called by the AuthorizationPlugin, the subclass should return the appropriate NSView for the requested SFViewType. The NSView and its contents should have the autoresize flags set as appropriate to allow for the view to be resized.
165 ///
166 /// Parameter `inType`: is the type of view being requested by the AuthorizationPlugin.
167 ///
168 /// NOTE: Currently a maximum width of 394 points is supported, but Apple reserves the right to change that in the future. Do not assume that the width of the NSView won't change.
169 #[unsafe(method(viewForType:))]
170 #[unsafe(method_family = none)]
171 pub unsafe fn viewForType(
172 &self,
173 in_type: SFViewType,
174 mtm: MainThreadMarker,
175 ) -> Option<Retained<NSView>>;
176 );
177}
178
179/// Methods declared on superclass `NSObject`.
180impl SFAuthorizationPluginView {
181 extern_methods!(
182 #[unsafe(method(init))]
183 #[unsafe(method_family = init)]
184 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
185
186 #[unsafe(method(new))]
187 #[unsafe(method_family = new)]
188 pub unsafe fn new() -> Retained<Self>;
189 );
190}
191
192/// SFHostControl.
193/// Methods called by the AuthorizationPlugin that instantiated the subclass or by the subclass.
194impl SFAuthorizationPluginView {
195 extern_methods!(
196 /// displayView is called in order to display the user interface provided by the subclass. If you subclass this method, be sure to call [super displayView]. displayView will raise an SFDisplayViewException exception if an error occurs displaying the authorization dialog.
197 #[unsafe(method(displayView))]
198 #[unsafe(method_family = none)]
199 pub unsafe fn displayView(&self);
200
201 /// The SFAuthorizationPluginView calls this when it would like to disable a button in the UI.
202 ///
203 /// Parameter `inButtonType`: the type of the button
204 ///
205 /// Parameter `inEnabled`: YES to enabled the button, NO to disable the button
206 #[unsafe(method(setButton:enabled:))]
207 #[unsafe(method_family = none)]
208 pub unsafe fn setButton_enabled(&self, in_button_type: SFButtonType, in_enabled: bool);
209
210 /// updateView is called in order to have a new or modified NSView loaded by the AuthorizationPlugin.
211 #[unsafe(method(updateView))]
212 #[unsafe(method_family = none)]
213 pub unsafe fn updateView(&self);
214 );
215}
216
217extern "C" {
218 /// [Apple's documentation](https://developer.apple.com/documentation/securityinterface/sfauthorizationpluginviewusernamekey?language=objc)
219 pub static SFAuthorizationPluginViewUserNameKey: Option<&'static NSString>;
220}
221
222extern "C" {
223 /// [Apple's documentation](https://developer.apple.com/documentation/securityinterface/sfauthorizationpluginviewusershortnamekey?language=objc)
224 pub static SFAuthorizationPluginViewUserShortNameKey: Option<&'static NSString>;
225}
226
227extern "C" {
228 /// [Apple's documentation](https://developer.apple.com/documentation/securityinterface/sfdisplayviewexception?language=objc)
229 pub static SFDisplayViewException: Option<&'static NSString>;
230}