Skip to main content

bitwarden_importers/
importer_client.rs

1use bitwarden_core::Client;
2#[cfg(feature = "wasm")]
3use wasm_bindgen::prelude::*;
4
5use crate::{ImportError, ImportOptions, ImportSummary, import::import_kdbx};
6
7#[allow(missing_docs)]
8#[cfg_attr(feature = "wasm", wasm_bindgen)]
9pub struct ImporterClient {
10    client: Client,
11}
12
13#[cfg_attr(feature = "wasm", wasm_bindgen)]
14impl ImporterClient {
15    fn new(client: Client) -> Self {
16        Self { client }
17    }
18
19    /// Import a KeePass KDBX (`.kdbx`) database and submit it to the server.
20    ///
21    /// Parses and decrypts the raw `.kdbx` bytes (unlocked with the password and/or key file),
22    /// encrypts the entries for the user's personal vault or the given organization, and submits
23    /// them to the import endpoint. Returns the counts of what was imported. Inputs larger than
24    /// 10 MiB are rejected with `KdbxFileTooLarge`.
25    pub async fn import_kdbx(
26        &self,
27        file: Vec<u8>,
28        password: Option<String>,
29        key_file: Option<Vec<u8>>,
30        options: ImportOptions,
31    ) -> Result<ImportSummary, ImportError> {
32        import_kdbx(&self.client, file, password, key_file, options).await
33    }
34}
35
36#[allow(missing_docs)]
37pub trait ImporterClientExt {
38    fn importers(&self) -> ImporterClient;
39}
40
41impl ImporterClientExt for Client {
42    fn importers(&self) -> ImporterClient {
43        ImporterClient::new(self.clone())
44    }
45}