sos_platform_authenticator/
local_auth.rs1#[cfg(not(target_os = "linux"))]
4mod supported {
5 use robius_authentication::{
6 AndroidText, BiometricStrength, Context, Policy, PolicyBuilder, Text,
7 WindowsText,
8 };
9
10 pub struct AuthenticateOptions {
12 pub biometrics: BiometricStrength,
14 pub password: bool,
16 pub android: AndroidText<'static, 'static, 'static>,
18 pub apple: &'static str,
20 pub windows: WindowsText<'static, 'static>,
22 }
23
24 impl Default for AuthenticateOptions {
25 fn default() -> Self {
26 Self {
27 biometrics: BiometricStrength::Strong,
28 password: true,
29 android: AndroidText {
30 title: "Authenticate",
31 subtitle: None,
32 description: None,
33 },
34 apple: "authenticate",
35 windows: WindowsText::new(
36 "Save Our Secrets",
37 "Verify your identity to authenticate",
38 )
39 .unwrap(),
40 }
41 }
42 }
43
44 pub fn authenticate(options: AuthenticateOptions) -> bool {
46 let policy: Policy = PolicyBuilder::new()
47 .biometrics(Some(options.biometrics))
48 .password(options.password)
49 .watch(true)
50 .build()
51 .unwrap();
52
53 let text: Text = Text {
54 android: options.android,
55 apple: options.apple,
56 windows: options.windows,
57 };
58
59 let context = Context::new(());
60 context.blocking_authenticate(text, &policy).is_ok()
61 }
62
63 pub fn supported() -> bool {
65 true
66 }
67}
68#[cfg(not(target_os = "linux"))]
69pub use supported::*;
70
71#[cfg(target_os = "linux")]
72mod unsupported {
73 #[derive(Default)]
75 pub struct AuthenticateOptions {}
76
77 pub fn authenticate(_options: AuthenticateOptions) -> bool {
79 false
80 }
81
82 pub fn supported() -> bool {
84 false
85 }
86}
87
88#[cfg(target_os = "linux")]
89pub use unsupported::*;