bitwarden_fido/
traits.rs

1use bitwarden_vault::{CipherListView, CipherView, EncryptionContext, Fido2CredentialNewView};
2use passkey::authenticator::UiHint;
3use thiserror::Error;
4
5#[allow(missing_docs)]
6#[derive(Debug, Error)]
7pub enum Fido2CallbackError {
8    #[error("The operation requires user interaction")]
9    UserInterfaceRequired,
10
11    #[error("The operation was cancelled by the user")]
12    OperationCancelled,
13
14    #[error("Unknown error: {0}")]
15    Unknown(String),
16}
17
18#[allow(missing_docs)]
19#[async_trait::async_trait]
20pub trait Fido2UserInterface: Send + Sync {
21    async fn check_user<'a>(
22        &self,
23        options: CheckUserOptions,
24        hint: UiHint<'a, CipherView>,
25    ) -> Result<CheckUserResult, Fido2CallbackError>;
26    async fn pick_credential_for_authentication(
27        &self,
28        available_credentials: Vec<CipherView>,
29    ) -> Result<CipherView, Fido2CallbackError>;
30    async fn check_user_and_pick_credential_for_creation(
31        &self,
32        options: CheckUserOptions,
33        new_credential: Fido2CredentialNewView,
34    ) -> Result<(CipherView, CheckUserResult), Fido2CallbackError>;
35    fn is_verification_enabled(&self) -> bool;
36}
37
38#[allow(missing_docs)]
39#[async_trait::async_trait]
40pub trait Fido2CredentialStore: Send + Sync {
41    async fn find_credentials(
42        &self,
43        ids: Option<Vec<Vec<u8>>>,
44        rip_id: String,
45        user_handle: Option<Vec<u8>>,
46    ) -> Result<Vec<CipherView>, Fido2CallbackError>;
47
48    async fn all_credentials(&self) -> Result<Vec<CipherListView>, Fido2CallbackError>;
49
50    async fn save_credential(&self, cred: EncryptionContext) -> Result<(), Fido2CallbackError>;
51}
52
53#[allow(missing_docs)]
54#[derive(Clone)]
55#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
56pub struct CheckUserOptions {
57    pub require_presence: bool,
58    pub require_verification: Verification,
59}
60
61#[allow(missing_docs)]
62#[derive(Clone)]
63#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
64pub enum Verification {
65    Discouraged,
66    Preferred,
67    Required,
68}
69
70#[allow(missing_docs)]
71pub struct CheckUserResult {
72    pub user_present: bool,
73    pub user_verified: bool,
74}