bitwarden_uniffi/vault/
mod.rs

1use bitwarden_vault::{CipherListView, TotpResponse};
2use chrono::{DateTime, Utc};
3
4use crate::error::{Error, Result};
5
6pub mod attachments;
7pub mod ciphers;
8pub mod collections;
9pub mod folders;
10pub mod password_history;
11
12#[derive(uniffi::Object)]
13pub struct VaultClient(pub(crate) bitwarden_vault::VaultClient);
14
15#[uniffi::export]
16impl VaultClient {
17    /// Folder operations
18    pub fn folders(&self) -> folders::FoldersClient {
19        folders::FoldersClient(self.0.folders())
20    }
21
22    /// Collections operations
23    pub fn collections(&self) -> collections::CollectionsClient {
24        collections::CollectionsClient(self.0.collections())
25    }
26
27    /// Ciphers operations
28    pub fn ciphers(&self) -> ciphers::CiphersClient {
29        ciphers::CiphersClient(self.0.ciphers())
30    }
31
32    /// Password history operations
33    pub fn password_history(&self) -> password_history::PasswordHistoryClient {
34        password_history::PasswordHistoryClient(self.0.password_history())
35    }
36
37    /// Attachment file operations
38    pub fn attachments(&self) -> attachments::AttachmentsClient {
39        attachments::AttachmentsClient(self.0.attachments())
40    }
41
42    /// Generate a TOTP code from a provided key.
43    ///
44    /// The key can be either:
45    /// - A base32 encoded string
46    /// - OTP Auth URI
47    /// - Steam URI
48    pub fn generate_totp(&self, key: String, time: Option<DateTime<Utc>>) -> Result<TotpResponse> {
49        Ok(self
50            .0
51            .totp()
52            .generate_totp(key, time)
53            .map_err(Error::Totp)?)
54    }
55
56    /// Generate a TOTP code from a provided cipher list view.
57    pub fn generate_totp_cipher_view(
58        &self,
59        view: CipherListView,
60        time: Option<DateTime<Utc>>,
61    ) -> Result<TotpResponse> {
62        Ok(self
63            .0
64            .totp()
65            .generate_totp_cipher_view(view, time)
66            .map_err(Error::Totp)?)
67    }
68}