bitwarden_exporters/exporter_client.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
use bitwarden_core::Client;
use bitwarden_vault::{Cipher, Collection, Folder};
use crate::{
export::{export_cxf, export_organization_vault, export_vault, import_cxf},
Account, ExportError, ExportFormat,
};
pub struct ExporterClient<'a> {
client: &'a Client,
}
impl<'a> ExporterClient<'a> {
fn new(client: &'a Client) -> Self {
Self { client }
}
pub fn export_vault(
&self,
folders: Vec<Folder>,
ciphers: Vec<Cipher>,
format: ExportFormat,
) -> Result<String, ExportError> {
export_vault(self.client, folders, ciphers, format)
}
pub fn export_organization_vault(
&self,
collections: Vec<Collection>,
ciphers: Vec<Cipher>,
format: ExportFormat,
) -> Result<String, ExportError> {
export_organization_vault(collections, ciphers, format)
}
/// Credential Exchange Format (CXF)
///
/// *Warning:* Expect this API to be unstable, and it will change in the future.
///
/// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
/// Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
pub fn export_cxf(
&self,
account: Account,
ciphers: Vec<Cipher>,
) -> Result<String, ExportError> {
export_cxf(self.client, account, ciphers)
}
/// Credential Exchange Format (CXF)
///
/// *Warning:* Expect this API to be unstable, and it will change in the future.
///
/// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
/// Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
pub fn import_cxf(&self, payload: String) -> Result<Vec<Cipher>, ExportError> {
import_cxf(self.client, payload)
}
}
pub trait ExporterClientExt<'a> {
fn exporters(&'a self) -> ExporterClient<'a>;
}
impl<'a> ExporterClientExt<'a> for Client {
fn exporters(&'a self) -> ExporterClient<'a> {
ExporterClient::new(self)
}
}