bitwarden_uniffi/tool/
mod.rs1use bitwarden_collections::collection::Collection;
2use bitwarden_exporters::{Account, ExportFormat};
3use bitwarden_generators::{
4 PassphraseGeneratorRequest, PasswordGeneratorRequest, UsernameGeneratorRequest,
5};
6use bitwarden_importers::{ImportOptions, ImportSummary};
7use bitwarden_vault::{Cipher, Folder};
8
9use crate::error::Result;
10
11mod sends;
12pub use sends::SendClient;
13
14mod ssh;
15pub use ssh::SshClient;
16
17#[derive(uniffi::Object)]
18pub struct GeneratorClients(pub(crate) bitwarden_generators::GeneratorClient);
19
20#[uniffi::export(async_runtime = "tokio")]
21impl GeneratorClients {
22 pub fn password(&self, settings: PasswordGeneratorRequest) -> Result<String> {
24 Ok(self.0.password(settings)?)
25 }
26
27 pub fn passphrase(&self, settings: PassphraseGeneratorRequest) -> Result<String> {
29 Ok(self.0.passphrase(settings)?)
30 }
31
32 pub fn password_rules(&self, rules: String) -> Result<PasswordGeneratorRequest> {
34 Ok(self.0.password_rules(rules)?)
35 }
36
37 pub async fn username(&self, settings: UsernameGeneratorRequest) -> Result<String> {
39 Ok(self.0.username(settings).await?)
40 }
41}
42
43#[derive(uniffi::Object)]
44pub struct ExporterClient(pub(crate) bitwarden_exporters::ExporterClient);
45
46#[uniffi::export(async_runtime = "tokio")]
47impl ExporterClient {
48 pub async fn export_vault(
50 &self,
51 folders: Vec<Folder>,
52 ciphers: Vec<Cipher>,
53 format: ExportFormat,
54 ) -> Result<String> {
55 Ok(self.0.export_vault(folders, ciphers, format).await?)
56 }
57
58 pub fn export_organization_vault(
60 &self,
61 collections: Vec<Collection>,
62 ciphers: Vec<Cipher>,
63 format: ExportFormat,
64 ) -> Result<String> {
65 Ok(self
66 .0
67 .export_organization_vault(collections, ciphers, format)?)
68 }
69
70 pub fn export_cxf(&self, account: Account, ciphers: Vec<Cipher>) -> Result<String> {
77 Ok(self.0.export_cxf(account, ciphers)?)
78 }
79
80 pub fn import_cxf(&self, payload: String) -> Result<Vec<Cipher>> {
87 Ok(self.0.import_cxf(payload)?)
88 }
89}
90
91#[derive(uniffi::Object)]
92pub struct ImporterClient(pub(crate) bitwarden_importers::ImporterClient);
93
94#[uniffi::export(async_runtime = "tokio")]
95impl ImporterClient {
96 pub async fn import_kdbx(
98 &self,
99 file: Vec<u8>,
100 password: Option<String>,
101 key_file: Option<Vec<u8>>,
102 options: ImportOptions,
103 ) -> Result<ImportSummary> {
104 Ok(self
105 .0
106 .import_kdbx(file, password, key_file, options)
107 .await?)
108 }
109}