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::{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).map_err(Error::Password)?)
24    }
25
26    /// Generate Passphrase
27    pub fn passphrase(&self, settings: PassphraseGeneratorRequest) -> Result<String> {
28        Ok(self.0.passphrase(settings).map_err(Error::Passphrase)?)
29    }
30
31    /// Generate Username
32    pub async fn username(&self, settings: UsernameGeneratorRequest) -> Result<String> {
33        Ok(self.0.username(settings).await.map_err(Error::Username)?)
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
50            .0
51            .export_vault(folders, ciphers, format)
52            .map_err(Error::Export)?)
53    }
54
55    /// Export organization vault
56    pub fn export_organization_vault(
57        &self,
58        collections: Vec<Collection>,
59        ciphers: Vec<Cipher>,
60        format: ExportFormat,
61    ) -> Result<String> {
62        Ok(self
63            .0
64            .export_organization_vault(collections, ciphers, format)
65            .map_err(Error::Export)?)
66    }
67
68    /// Credential Exchange Format (CXF)
69    ///
70    /// *Warning:* Expect this API to be unstable, and it will change in the future.
71    ///
72    /// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
73    /// Ideally the output should be immediately deserialized to [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
74    pub fn export_cxf(&self, account: Account, ciphers: Vec<Cipher>) -> Result<String> {
75        Ok(self.0.export_cxf(account, ciphers).map_err(Error::Export)?)
76    }
77
78    /// Credential Exchange Format (CXF)
79    ///
80    /// *Warning:* Expect this API to be unstable, and it will change in the future.
81    ///
82    /// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
83    /// Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
84    pub fn import_cxf(&self, payload: String) -> Result<Vec<Cipher>> {
85        Ok(self.0.import_cxf(payload).map_err(Error::Export)?)
86    }
87}