objc2_local_authentication/generated/
LARight.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_foundation::*;
7
8use crate::*;
9
10/// Each of the different states of a right
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/localauthentication/larightstate?language=objc)
13// NS_ENUM
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct LARightState(pub NSInteger);
17impl LARightState {
18    /// Right has not been evaluated yet.
19    ///
20    /// This is the initial state of
21    /// `LARight`and changes when
22    /// `authorize`method is called.
23    #[doc(alias = "LARightStateUnknown")]
24    pub const Unknown: Self = Self(0);
25    /// Requirements are currently being evaluated.
26    ///
27    /// This happens after calling
28    /// `authorize`method but before the user has granted the right.
29    #[doc(alias = "LARightStateAuthorizing")]
30    pub const Authorizing: Self = Self(1);
31    /// Authorization was granted
32    ///
33    /// This can be achieved by succesful authorization.
34    #[doc(alias = "LARightStateAuthorized")]
35    pub const Authorized: Self = Self(2);
36    /// Authorization was rejected.
37    ///
38    /// This can be caused by several reasons. For example requirements were not satisified or user rejects to authorize.
39    #[doc(alias = "LARightStateNotAuthorized")]
40    pub const NotAuthorized: Self = Self(3);
41}
42
43unsafe impl Encode for LARightState {
44    const ENCODING: Encoding = NSInteger::ENCODING;
45}
46
47unsafe impl RefEncode for LARightState {
48    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
49}
50
51extern_class!(
52    /// Groups a set of requirements that need to be satisfied in order to grant access to certain resource or operation
53    ///
54    /// See also [Apple's documentation](https://developer.apple.com/documentation/localauthentication/laright?language=objc)
55    #[unsafe(super(NSObject))]
56    #[derive(Debug, PartialEq, Eq, Hash)]
57    pub struct LARight;
58);
59
60unsafe impl NSObjectProtocol for LARight {}
61
62impl LARight {
63    extern_methods!(
64        /// Provides the current authorization state of the
65        /// `LARight`instance
66        #[unsafe(method(state))]
67        #[unsafe(method_family = none)]
68        pub unsafe fn state(&self) -> LARightState;
69
70        /// An application-supplied integer that can be used to identify right intances. The default value is
71        /// `0.`
72        #[unsafe(method(tag))]
73        #[unsafe(method_family = none)]
74        pub unsafe fn tag(&self) -> NSInteger;
75
76        /// Setter for [`tag`][Self::tag].
77        #[unsafe(method(setTag:))]
78        #[unsafe(method_family = none)]
79        pub unsafe fn setTag(&self, tag: NSInteger);
80
81        /// Constructs a right using default authorization requirements
82        ///
83        /// For authorizing a right with default requirements a user will be asked to authenticate using biometry or the device passcode.
84        ///
85        /// Returns: `LARight`instance
86        #[unsafe(method(init))]
87        #[unsafe(method_family = init)]
88        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
89
90        #[cfg(feature = "LARequirement")]
91        /// Constructs a right that will be granted only when the given
92        /// `LAAuthenticationRequirement`is statisfied.
93        ///
94        /// Parameter `requirement`: Requirement that needs to be satisfied to authorize the right
95        ///
96        /// Returns: `LARight`instance
97        #[unsafe(method(initWithRequirement:))]
98        #[unsafe(method_family = init)]
99        pub unsafe fn initWithRequirement(
100            this: Allocated<Self>,
101            requirement: &LAAuthenticationRequirement,
102        ) -> Retained<Self>;
103
104        #[cfg(feature = "block2")]
105        /// Tries to authorize the right.
106        ///
107        /// Parameter `localizedReason`: Localized explanation for the authorization. Appears in the UI presented to the user.
108        ///
109        /// Parameter `handler`: Completion handler called after the authorization finishes. Returns an error when the authorization fails.
110        #[unsafe(method(authorizeWithLocalizedReason:completion:))]
111        #[unsafe(method_family = none)]
112        pub unsafe fn authorizeWithLocalizedReason_completion(
113            &self,
114            localized_reason: &NSString,
115            handler: &block2::Block<dyn Fn(*mut NSError)>,
116        );
117
118        #[cfg(feature = "block2")]
119        /// Checks whether the client can eventually be granted the right.
120        ///
121        /// Parameter `handler`: Completion handler. Returns
122        /// `nil`if the right can be authorized or an error otherwise.
123        #[unsafe(method(checkCanAuthorizeWithCompletion:))]
124        #[unsafe(method_family = none)]
125        pub unsafe fn checkCanAuthorizeWithCompletion(
126            &self,
127            handler: &block2::Block<dyn Fn(*mut NSError)>,
128        );
129
130        #[cfg(feature = "block2")]
131        /// Invalidates a previously authorized right.
132        ///
133        /// Parameter `handler`: Completion handler called after the right is deauthorized.
134        #[unsafe(method(deauthorizeWithCompletion:))]
135        #[unsafe(method_family = none)]
136        pub unsafe fn deauthorizeWithCompletion(&self, handler: &block2::Block<dyn Fn()>);
137    );
138}
139
140/// Methods declared on superclass `NSObject`.
141impl LARight {
142    extern_methods!(
143        #[unsafe(method(new))]
144        #[unsafe(method_family = new)]
145        pub unsafe fn new() -> Retained<Self>;
146    );
147}