Skip to content

Commit 27d8d4b

Browse files
committed
Add Account struct
1 parent cc9a081 commit 27d8d4b

File tree

6 files changed

+46
-19
lines changed

6 files changed

+46
-19
lines changed

crates/bitwarden-exporters/src/client_exporter.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use bitwarden_vault::{Cipher, Collection, Folder};
33

44
use crate::{
55
export::{export_cxf, export_organization_vault, export_vault},
6-
ExportError, ExportFormat,
6+
Account, ExportError, ExportFormat,
77
};
88

99
pub struct ClientExporters<'a> {
@@ -33,8 +33,12 @@ impl<'a> ClientExporters<'a> {
3333
export_organization_vault(collections, ciphers, format)
3434
}
3535

36-
pub fn export_cxf(&self, ciphers: Vec<Cipher>) -> Result<String, ExportError> {
37-
export_cxf(self.client, ciphers)
36+
pub fn export_cxf(
37+
&self,
38+
account: Account,
39+
ciphers: Vec<Cipher>,
40+
) -> Result<String, ExportError> {
41+
export_cxf(self.client, account, ciphers)
3842
}
3943
}
4044

crates/bitwarden-exporters/src/cxp/mod.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,42 @@ use bitwarden_crypto::generate_random_bytes;
22
use chrono::Utc;
33
use credential_exchange_types::{
44
format::{
5-
Account, BasicAuthCredential, Credential, EditableField, FieldType, Header, Item, ItemType,
5+
Account as CxpAccount, BasicAuthCredential, Credential, EditableField, FieldType, Header,
6+
Item, ItemType,
67
},
78
B64Url,
89
};
10+
use uuid::Uuid;
911

1012
use crate::{Cipher, CipherType, Login};
1113

1214
mod error;
1315
pub use error::CxpError;
1416

15-
pub(crate) fn build_cxf(ciphers: Vec<Cipher>) -> Result<String, CxpError> {
17+
#[derive(Debug)]
18+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
19+
pub struct Account {
20+
id: Uuid,
21+
email: String,
22+
name: Option<String>,
23+
}
24+
25+
pub(crate) fn build_cxf(account: Account, ciphers: Vec<Cipher>) -> Result<String, CxpError> {
1626
let items: Vec<Item> = ciphers.into_iter().map(|cipher| cipher.into()).collect();
1727

1828
let header = Header {
1929
version: 0,
2030
exporter: "Bitwarden".to_string(),
2131
timestamp: Utc::now().timestamp() as u64,
22-
accounts: vec![Account {
23-
id: todo!(),
24-
user_name: todo!(),
25-
email: todo!(),
26-
full_name: todo!(),
27-
icon: todo!(),
28-
collections: todo!(),
32+
accounts: vec![CxpAccount {
33+
id: account.id.as_bytes().as_slice().into(),
34+
user_name: "".to_owned(),
35+
email: account.email,
36+
full_name: account.name,
37+
icon: None,
38+
collections: vec![],
2939
items,
30-
extensions: todo!(),
40+
extensions: None,
3141
}],
3242
};
3343

crates/bitwarden-exporters/src/export.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use bitwarden_crypto::KeyDecryptable;
33
use bitwarden_vault::{Cipher, CipherView, Collection, Folder, FolderView};
44

55
use crate::{
6-
csv::export_csv, cxp::build_cxf, encrypted_json::export_encrypted_json, json::export_json,
6+
csv::export_csv,
7+
cxp::{build_cxf, Account},
8+
encrypted_json::export_encrypted_json,
9+
json::export_json,
710
ExportError, ExportFormat,
811
};
912

@@ -42,12 +45,16 @@ pub(crate) fn export_organization_vault(
4245
todo!();
4346
}
4447

45-
pub(crate) fn export_cxf(client: &Client, ciphers: Vec<Cipher>) -> Result<String, ExportError> {
48+
pub(crate) fn export_cxf(
49+
client: &Client,
50+
account: Account,
51+
ciphers: Vec<Cipher>,
52+
) -> Result<String, ExportError> {
4653
let enc = client.internal.get_encryption_settings()?;
4754
let key = enc.get_key(&None)?;
4855

4956
let ciphers: Vec<CipherView> = ciphers.decrypt_with_key(key)?;
5057
let ciphers: Vec<crate::Cipher> = ciphers.into_iter().flat_map(|c| c.try_into()).collect();
5158

52-
Ok(build_cxf(ciphers)?)
59+
Ok(build_cxf(account, ciphers)?)
5360
}

crates/bitwarden-exporters/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ use uuid::Uuid;
66

77
#[cfg(feature = "uniffi")]
88
uniffi::setup_scaffolding!();
9+
#[cfg(feature = "uniffi")]
10+
mod uniffi_support;
911

1012
mod client_exporter;
1113
mod csv;
1214
mod cxp;
15+
pub use cxp::Account;
1316
mod encrypted_json;
1417
mod json;
1518
mod models;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use uuid::Uuid;
2+
3+
uniffi::ffi_converter_forward!(Uuid, bitwarden_core::UniFfiTag, crate::UniFfiTag);

crates/bitwarden-uniffi/src/tool/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use bitwarden_exporters::{ClientExportersExt, ExportFormat};
3+
use bitwarden_exporters::{Account, ClientExportersExt, ExportFormat};
44
use bitwarden_generators::{
55
ClientGeneratorExt, PassphraseGeneratorRequest, PasswordGeneratorRequest,
66
UsernameGeneratorRequest,
@@ -91,12 +91,12 @@ impl ClientExporters {
9191
///
9292
/// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
9393
/// Ideally the output should be immediately deserialized to [ASExportedCredentialData](https://developer.apple.com/documentation/authenticationservices/asexportedcredentialdata).
94-
pub fn export_cxf(&self, ciphers: Vec<Cipher>) -> Result<String> {
94+
pub fn export_cxf(&self, account: Account, ciphers: Vec<Cipher>) -> Result<String> {
9595
Ok(self
9696
.0
9797
.0
9898
.exporters()
99-
.export_cxf(ciphers)
99+
.export_cxf(account, ciphers)
100100
.map_err(Error::ExportError)?)
101101
}
102102
}

0 commit comments

Comments
 (0)