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
60extern_conformance!(
61    unsafe impl NSObjectProtocol for LARight {}
62);
63
64impl LARight {
65    extern_methods!(
66        /// Provides the current authorization state of the
67        /// `LARight`instance
68        #[unsafe(method(state))]
69        #[unsafe(method_family = none)]
70        pub unsafe fn state(&self) -> LARightState;
71
72        /// An application-supplied integer that can be used to identify right intances. The default value is
73        /// `0.`
74        #[unsafe(method(tag))]
75        #[unsafe(method_family = none)]
76        pub unsafe fn tag(&self) -> NSInteger;
77
78        /// Setter for [`tag`][Self::tag].
79        #[unsafe(method(setTag:))]
80        #[unsafe(method_family = none)]
81        pub unsafe fn setTag(&self, tag: NSInteger);
82
83        /// Constructs a right using default authorization requirements
84        ///
85        /// For authorizing a right with default requirements a user will be asked to authenticate using biometry or the device passcode.
86        ///
87        /// Returns: `LARight`instance
88        #[unsafe(method(init))]
89        #[unsafe(method_family = init)]
90        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
91
92        #[cfg(feature = "LARequirement")]
93        /// Constructs a right that will be granted only when the given
94        /// `LAAuthenticationRequirement`is statisfied.
95        ///
96        /// Parameter `requirement`: Requirement that needs to be satisfied to authorize the right
97        ///
98        /// Returns: `LARight`instance
99        #[unsafe(method(initWithRequirement:))]
100        #[unsafe(method_family = init)]
101        pub unsafe fn initWithRequirement(
102            this: Allocated<Self>,
103            requirement: &LAAuthenticationRequirement,
104        ) -> Retained<Self>;
105
106        #[cfg(feature = "block2")]
107        /// Tries to authorize the right.
108        ///
109        /// Parameter `localizedReason`: Localized explanation for the authorization. Appears in the UI presented to the user.
110        ///
111        /// Parameter `handler`: Completion handler called after the authorization finishes. Returns an error when the authorization fails.
112        #[unsafe(method(authorizeWithLocalizedReason:completion:))]
113        #[unsafe(method_family = none)]
114        pub unsafe fn authorizeWithLocalizedReason_completion(
115            &self,
116            localized_reason: &NSString,
117            handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
118        );
119
120        #[cfg(feature = "block2")]
121        /// Checks whether the client can eventually be granted the right.
122        ///
123        /// Parameter `handler`: Completion handler. Returns
124        /// `nil`if the right can be authorized or an error otherwise.
125        #[unsafe(method(checkCanAuthorizeWithCompletion:))]
126        #[unsafe(method_family = none)]
127        pub unsafe fn checkCanAuthorizeWithCompletion(
128            &self,
129            handler: &block2::DynBlock<dyn Fn(*mut NSError)>,
130        );
131
132        #[cfg(feature = "block2")]
133        /// Invalidates a previously authorized right.
134        ///
135        /// Parameter `handler`: Completion handler called after the right is deauthorized.
136        #[unsafe(method(deauthorizeWithCompletion:))]
137        #[unsafe(method_family = none)]
138        pub unsafe fn deauthorizeWithCompletion(&self, handler: &block2::DynBlock<dyn Fn()>);
139    );
140}
141
142/// Methods declared on superclass `NSObject`.
143impl LARight {
144    extern_methods!(
145        #[unsafe(method(new))]
146        #[unsafe(method_family = new)]
147        pub unsafe fn new() -> Retained<Self>;
148    );
149}