bitwarden_uniffi/tool/
mod.rs1use 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 pub fn password(&self, settings: PasswordGeneratorRequest) -> Result<String> {
22 Ok(self.0.password(settings).map_err(Error::Password)?)
23 }
24
25 pub fn passphrase(&self, settings: PassphraseGeneratorRequest) -> Result<String> {
27 Ok(self.0.passphrase(settings).map_err(Error::Passphrase)?)
28 }
29
30 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 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 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 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 pub fn import_cxf(&self, payload: String) -> Result<Vec<Cipher>> {
84 Ok(self.0.import_cxf(payload).map_err(Error::Export)?)
85 }
86}