bitwarden_uniffi/tool/
mod.rs

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