bitwarden_uniffi/vault/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::sync::Arc;

use bitwarden::{
    error::Error,
    vault::{ClientVaultExt, TotpResponse},
};
use bitwarden_vault::CipherListView;
use chrono::{DateTime, Utc};

use crate::{error::Result, Client};

pub mod attachments;
pub mod ciphers;
pub mod collections;
pub mod folders;
pub mod password_history;

#[derive(uniffi::Object)]
pub struct ClientVault(pub(crate) Arc<Client>);

#[uniffi::export]
impl ClientVault {
    /// Folder operations
    pub fn folders(self: Arc<Self>) -> Arc<folders::ClientFolders> {
        Arc::new(folders::ClientFolders(self.0.clone()))
    }

    /// Collections operations
    pub fn collections(self: Arc<Self>) -> Arc<collections::ClientCollections> {
        Arc::new(collections::ClientCollections(self.0.clone()))
    }

    /// Ciphers operations
    pub fn ciphers(self: Arc<Self>) -> Arc<ciphers::ClientCiphers> {
        Arc::new(ciphers::ClientCiphers(self.0.clone()))
    }

    /// Password history operations
    pub fn password_history(self: Arc<Self>) -> Arc<password_history::ClientPasswordHistory> {
        Arc::new(password_history::ClientPasswordHistory(self.0.clone()))
    }

    /// Attachment file operations
    pub fn attachments(self: Arc<Self>) -> Arc<attachments::ClientAttachments> {
        Arc::new(attachments::ClientAttachments(self.0.clone()))
    }

    /// Generate a TOTP code from a provided key.
    ///
    /// The key can be either:
    /// - A base32 encoded string
    /// - OTP Auth URI
    /// - Steam URI
    pub fn generate_totp(&self, key: String, time: Option<DateTime<Utc>>) -> Result<TotpResponse> {
        Ok(self
            .0
             .0
            .vault()
            .generate_totp(key, time)
            .map_err(Error::Totp)?)
    }

    /// Generate a TOTP code from a provided cipher list view.
    pub fn generate_totp_cipher_view(
        &self,
        view: CipherListView,
        time: Option<DateTime<Utc>>,
    ) -> Result<TotpResponse> {
        Ok(self
            .0
             .0
            .vault()
            .generate_totp_cipher_view(view, time)
            .map_err(Error::Totp)?)
    }
}