bitwarden_uniffi/tool/
mod.rs

1use bitwarden_exporters::{Account, ExportFormat};
2use bitwarden_generators::{
3    PassphraseGeneratorRequest, PasswordGeneratorRequest, UsernameGeneratorRequest,
4};
5use bitwarden_vault::{Cipher, Collection, Folder};
6
7use crate::error::{Error, Result};
8
9mod sends;
10pub use sends::SendClient;
11
12mod ssh;
13pub use ssh::SshClient;
14
15#[derive(uniffi::Object)]
16pub struct GeneratorClients(pub(crate) bitwarden_generators::GeneratorClient);
17
18#[uniffi::export(async_runtime = "tokio")]
19impl GeneratorClients {
20    /// Generate Password
21    pub fn password(&self, settings: PasswordGeneratorRequest) -> Result<String> {
22        Ok(self.0.password(settings).map_err(Error::Password)?)
23    }
24
25    /// Generate Passphrase
26    pub fn passphrase(&self, settings: PassphraseGeneratorRequest) -> Result<String> {
27        Ok(self.0.passphrase(settings).map_err(Error::Passphrase)?)
28    }
29
30    /// Generate Username
31    pub async fn username(&self, settings: UsernameGeneratorRequest) -> Result<String> {
32        Ok(self.0.username(settings).await.map_err(Error::Username)?)
33    }
34}
35
36#[derive(uniffi::Object)]
37pub struct ExporterClient(pub(crate) bitwarden_exporters::ExporterClient);
38
39#[uniffi::export]
40impl ExporterClient {
41    /// Export user vault
42    pub fn export_vault(
43        &self,
44        folders: Vec<Folder>,
45        ciphers: Vec<Cipher>,
46        format: ExportFormat,
47    ) -> Result<String> {
48        Ok(self
49            .0
50            .export_vault(folders, ciphers, format)
51            .map_err(Error::Export)?)
52    }
53
54    /// Export organization vault
55    pub fn export_organization_vault(
56        &self,
57        collections: Vec<Collection>,
58        ciphers: Vec<Cipher>,
59        format: ExportFormat,
60    ) -> Result<String> {
61        Ok(self
62            .0
63            .export_organization_vault(collections, ciphers, format)
64            .map_err(Error::Export)?)
65    }
66
67    /// Credential Exchange Format (CXF)
68    ///
69    /// *Warning:* Expect this API to be unstable, and it will change in the future.
70    ///
71    /// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
72    /// Ideally the output should be immediately deserialized to [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
73    pub fn export_cxf(&self, account: Account, ciphers: Vec<Cipher>) -> Result<String> {
74        Ok(self.0.export_cxf(account, ciphers).map_err(Error::Export)?)
75    }
76
77    /// Credential Exchange Format (CXF)
78    ///
79    /// *Warning:* Expect this API to be unstable, and it will change in the future.
80    ///
81    /// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
82    /// Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
83    pub fn import_cxf(&self, payload: String) -> Result<Vec<Cipher>> {
84        Ok(self.0.import_cxf(payload).map_err(Error::Export)?)
85    }
86}