bitwarden_shared_unlock/drivers.rs
1//! Drivers that need to be implemented per platform for the shared unlock system.
2
3use bitwarden_core::UserId;
4use bitwarden_crypto::SymmetricCryptoKey;
5
6/// Trait that implmeents the device's shared unlock driver. These functions need to be implemented
7/// in order to allow the shared unlock system to function.
8#[async_trait::async_trait]
9pub trait SharedUnlockDriver {
10 /// Lock the user with the given ID.
11 async fn lock_user(&self, user_id: UserId) -> Result<(), ()>;
12 /// Unlock the user with the given ID.
13 async fn unlock_user(&self, user_id: UserId, user_key: SymmetricCryptoKey) -> Result<(), ()>;
14 /// List all users this device has an account for, locked or unlocked.
15 async fn list_users(&self) -> Vec<UserId>;
16 /// Get vault_url for the user with the given ID, if available. This is used to verify IPC
17 /// message sources
18 async fn get_vault_url(&self, user_id: UserId) -> Option<String>;
19 /// Suppress the vault timeout for the given user for the specified duration.
20 /// Called when a sync is received from this device's leader, keeping the shared session active.
21 async fn suppress_vault_timeout(
22 &self,
23 user_id: UserId,
24 suppression_duration: std::time::Duration,
25 );
26 /// Discovers the endpoint of the peer above this one in the device hierarchy or none
27 /// if this device is at the top of the hierarchy. The local peer disables vault timeout
28 /// if it is not at the top of the hierarchy.
29 async fn discover_leader(&self) -> Option<bitwarden_ipc::Endpoint>;
30}