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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Copyright (C) 2026 Qualia2FA contributors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3 of the License, or (at your option) any
// later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, see <https://www.gnu.org/licenses/>.
//! The platform-independent interface.
//!
//! The application holds one value that implements [`AuthBoundKeyStore`] and asks it
//! three questions: is this platform able to do it, wrap the master key, and unwrap
//! it. Each backend answers with its own platform mechanism; the caller does not
//! choose between them.
use crateMasterKey;
use crate::;
/// The platform mechanism behind one auth-bound store.
///
/// The identifier is written into the blob (see [`crate::format`]) and therefore must
/// never change for an existing backend: bytes written by an older build depend on it.
/// A new backend takes a new number.
/// What a store can do on this machine, asked **before** the user is offered the
/// biometric path.
///
/// The three cases are deliberately distinct:
///
/// - [`Availability::Available`]: the platform mechanism works. `hardware_backed`
/// states what the platform actually reported — it must not be guessed.
/// - [`Availability::Unavailable`]: the platform has the mechanism, but this machine or
/// this user cannot use it right now (no Windows Hello enrolment, a removed
/// fingerprint, an Android version below 28). The password path must be used.
/// - [`Availability::Unsupported`]: this build has no backend for the platform at all.
/// A store whose key is bound to the platform's user authentication.
///
/// # What a backend must guarantee
///
/// The wrapped bytes are encrypted with material that the **platform** releases only
/// after the user authenticates. A backend that asks for authentication and then
/// decrypts with a key the process already holds is not implementing this trait; it is
/// a user-interface prompt with no cryptographic effect.
///
/// # Threading
///
/// The store is `Send + Sync` because an application shares one instance between the
/// user interface and background work. A backend that uses a platform handle which is
/// not thread-safe must serialize its own calls; the trait does not permit returning
/// "busy" as a normal answer.
///
/// # Errors
///
/// Every method may return [`Error::Unavailable`] when the platform stops being usable
/// between two calls (the user removed the PIN, the credential was invalidated). That
/// is a state the caller reports and recovers from through the password path, not a
/// crash.