Skip to main content

tauri_plugin_biometric/
models.rs

1// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5use serde::{Deserialize, Serialize};
6
7/// Options for [`Biometric::authenticate`](crate::Biometric::authenticate).
8#[derive(Debug, Default, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct AuthOptions {
11    /// Enables authentication using the device's password. This feature is available on Android, iOS and macOS.
12    pub allow_device_credential: bool,
13    /// Label for the Cancel button. This feature is available on Android, iOS and macOS.
14    pub cancel_title: Option<String>,
15    /// The plain data that must be encrypted after successful biometric authentication. **Android only.**
16    pub data_to_encrypt: Option<String>,
17    /// The encrypted data that must be decrypted after successful biometric authentication. **Android only.**
18    pub data_to_decrypt: Option<String>,
19    /// Specifies the text displayed on the fallback button if biometric authentication fails. This feature is available on iOS and macOS only.
20    pub fallback_title: Option<String>,
21    /// Title indicating the purpose of biometric verification. This feature is available Android only.
22    pub title: Option<String>,
23    /// SubTitle providing contextual information of biometric verification. This feature is available Android only.
24    pub subtitle: Option<String>,
25    /// Specifies whether additional user confirmation is required, such as pressing a button after successful biometric authentication. This feature is available Android only.
26    pub confirmation_required: Option<bool>,
27}
28
29/// The kind of biometry hardware detected on the device.
30#[derive(Debug, Clone, serde_repr::Deserialize_repr, serde_repr::Serialize_repr)]
31#[repr(u8)]
32pub enum BiometryType {
33    /// No biometry hardware is available, or it is not enrolled with the operating system.
34    None = 0,
35    /// Fingerprint authentication (Apple Touch ID or Android fingerprint).
36    TouchID = 1,
37    /// Face authentication (Apple Face ID or Android face authentication).
38    FaceID = 2,
39}
40
41/// The result of [`Biometric::status`](crate::Biometric::status), describing whether biometric
42/// authentication can currently be used.
43#[derive(Debug, Clone, Deserialize, Serialize)]
44#[serde(rename_all = "camelCase")]
45pub struct Status {
46    /// Whether the device can currently authenticate using biometrics.
47    pub is_available: bool,
48    /// The kind of biometry hardware detected on the device, even when [`Self::is_available`] is `false`.
49    pub biometry_type: BiometryType,
50    /// A human-readable reason why biometric authentication is unavailable. Only set when
51    /// [`Self::is_available`] is `false`.
52    pub error: Option<String>,
53    /// A platform-specific error code describing why biometric authentication is unavailable.
54    /// Only set when [`Self::is_available`] is `false`.
55    pub error_code: Option<String>,
56}
57
58/// The result of [`Biometric::biometric_cipher`](crate::Biometric::biometric_cipher).
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct CipherResult {
61    /// The encrypted or decrypted data.
62    pub data: String,
63}