Skip to main content

bitwarden_exporters/
exporter_client.rs

1use bitwarden_collections::collection::Collection;
2use bitwarden_core::Client;
3use bitwarden_vault::{Cipher, EncryptionContext, Folder};
4
5use crate::{
6    Account, ExportError, ExportFormat,
7    export::{export_cxf, export_organization_vault, export_vault, import_cxf},
8};
9
10#[allow(missing_docs)]
11#[bitwarden_ffi::wasm_object]
12pub struct ExporterClient {
13    client: Client,
14}
15
16#[bitwarden_ffi::wasm_export]
17impl ExporterClient {
18    fn new(client: Client) -> Self {
19        Self { client }
20    }
21
22    #[allow(missing_docs)]
23    pub async fn export_vault(
24        &self,
25        folders: Vec<Folder>,
26        ciphers: Vec<Cipher>,
27        format: ExportFormat,
28    ) -> Result<String, ExportError> {
29        export_vault(&self.client, folders, ciphers, format).await
30    }
31
32    #[allow(missing_docs)]
33    pub fn export_organization_vault(
34        &self,
35        collections: Vec<Collection>,
36        ciphers: Vec<Cipher>,
37        format: ExportFormat,
38    ) -> Result<String, ExportError> {
39        export_organization_vault(collections, ciphers, format)
40    }
41
42    /// Credential Exchange Format (CXF)
43    ///
44    /// *Warning:* Expect this API to be unstable, and it will change in the future.
45    ///
46    /// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
47    /// Ideally, the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
48    pub fn export_cxf(
49        &self,
50        account: Account,
51        ciphers: Vec<Cipher>,
52    ) -> Result<String, ExportError> {
53        export_cxf(&self.client, account, ciphers)
54    }
55
56    /// Credential Exchange Format (CXF)
57    ///
58    /// *Warning:* Expect this API to be unstable, and it will change in the future.
59    ///
60    /// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
61    /// Ideally, the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
62    ///
63    /// Each returned [`EncryptionContext`] carries the encrypted cipher along with the user it was
64    /// encrypted for and the id of the key it was wrapped under.
65    pub fn import_cxf(&self, payload: String) -> Result<Vec<EncryptionContext>, ExportError> {
66        import_cxf(&self.client, payload)
67    }
68}
69
70#[allow(missing_docs)]
71pub trait ExporterClientExt {
72    fn exporters(&self) -> ExporterClient;
73}
74
75impl ExporterClientExt for Client {
76    fn exporters(&self) -> ExporterClient {
77        ExporterClient::new(self.clone())
78    }
79}