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