bitwarden_uniffi/vault/
mod.rs

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