diff --git a/Cargo.lock b/Cargo.lock index 5755f5cd5..480a1d3bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -493,7 +493,9 @@ name = "bitwarden-exporters" version = "0.5.0" dependencies = [ "base64 0.22.1", + "bitwarden-core", "bitwarden-crypto", + "bitwarden-vault", "chrono", "csv", "serde", @@ -584,7 +586,6 @@ dependencies = [ "bitwarden-api-api", "bitwarden-core", "bitwarden-crypto", - "bitwarden-exporters", "chrono", "hmac", "rand", diff --git a/crates/bitwarden-exporters/Cargo.toml b/crates/bitwarden-exporters/Cargo.toml index b607879ba..ac302526c 100644 --- a/crates/bitwarden-exporters/Cargo.toml +++ b/crates/bitwarden-exporters/Cargo.toml @@ -16,7 +16,9 @@ keywords.workspace = true [dependencies] base64 = ">=0.21.2, <0.23" +bitwarden-core = { workspace = true } bitwarden-crypto = { workspace = true } +bitwarden-vault = { workspace = true } chrono = { version = ">=0.4.26, <0.5", features = [ "clock", "serde", diff --git a/crates/bitwarden-exporters/src/lib.rs b/crates/bitwarden-exporters/src/lib.rs index 762556388..e754a64d1 100644 --- a/crates/bitwarden-exporters/src/lib.rs +++ b/crates/bitwarden-exporters/src/lib.rs @@ -10,8 +10,8 @@ use crate::csv::export_csv; mod json; use json::export_json; mod encrypted_json; - use encrypted_json::export_encrypted_json; +mod models; pub enum Format { Csv, diff --git a/crates/bitwarden-vault/src/exporters.rs b/crates/bitwarden-exporters/src/models.rs similarity index 80% rename from crates/bitwarden-vault/src/exporters.rs rename to crates/bitwarden-exporters/src/models.rs index 3b228f231..1d56e7233 100644 --- a/crates/bitwarden-vault/src/exporters.rs +++ b/crates/bitwarden-exporters/src/models.rs @@ -1,8 +1,9 @@ use bitwarden_core::{require, MissingFieldError}; +use bitwarden_vault::{ + CipherType, CipherView, FieldView, FolderView, LoginUriView, SecureNoteType, +}; -use crate::{login::LoginUriView, CipherType, CipherView, FieldView, FolderView, SecureNoteType}; - -impl TryFrom for bitwarden_exporters::Folder { +impl TryFrom for crate::Folder { type Error = MissingFieldError; fn try_from(value: FolderView) -> Result { @@ -13,14 +14,14 @@ impl TryFrom for bitwarden_exporters::Folder { } } -impl TryFrom for bitwarden_exporters::Cipher { +impl TryFrom for crate::Cipher { type Error = MissingFieldError; fn try_from(value: CipherView) -> Result { let r = match value.r#type { CipherType::Login => { let l = require!(value.login); - bitwarden_exporters::CipherType::Login(Box::new(bitwarden_exporters::Login { + crate::CipherType::Login(Box::new(crate::Login { username: l.username, password: l.password, login_uris: l @@ -32,18 +33,16 @@ impl TryFrom for bitwarden_exporters::Cipher { totp: l.totp, })) } - CipherType::SecureNote => bitwarden_exporters::CipherType::SecureNote(Box::new( - bitwarden_exporters::SecureNote { - r#type: value - .secure_note - .map(|t| t.r#type) - .unwrap_or(SecureNoteType::Generic) - .into(), - }, - )), + CipherType::SecureNote => crate::CipherType::SecureNote(Box::new(crate::SecureNote { + r#type: value + .secure_note + .map(|t| t.r#type) + .unwrap_or(SecureNoteType::Generic) + .into(), + })), CipherType::Card => { let c = require!(value.card); - bitwarden_exporters::CipherType::Card(Box::new(bitwarden_exporters::Card { + crate::CipherType::Card(Box::new(crate::Card { cardholder_name: c.cardholder_name, exp_month: c.exp_month, exp_year: c.exp_year, @@ -54,7 +53,7 @@ impl TryFrom for bitwarden_exporters::Cipher { } CipherType::Identity => { let i = require!(value.identity); - bitwarden_exporters::CipherType::Identity(Box::new(bitwarden_exporters::Identity { + crate::CipherType::Identity(Box::new(crate::Identity { title: i.title, first_name: i.first_name, middle_name: i.middle_name, @@ -98,7 +97,7 @@ impl TryFrom for bitwarden_exporters::Cipher { } } -impl From for bitwarden_exporters::Field { +impl From for crate::Field { fn from(value: FieldView) -> Self { Self { name: value.name, @@ -109,7 +108,7 @@ impl From for bitwarden_exporters::Field { } } -impl From for bitwarden_exporters::LoginUri { +impl From for crate::LoginUri { fn from(value: LoginUriView) -> Self { Self { r#match: value.r#match.map(|v| v as u8), @@ -118,20 +117,20 @@ impl From for bitwarden_exporters::LoginUri { } } -impl From for bitwarden_exporters::SecureNoteType { +impl From for crate::SecureNoteType { fn from(value: SecureNoteType) -> Self { match value { - SecureNoteType::Generic => bitwarden_exporters::SecureNoteType::Generic, + SecureNoteType::Generic => crate::SecureNoteType::Generic, } } } #[cfg(test)] mod tests { + use bitwarden_vault::{CipherRepromptType, LoginView}; use chrono::{DateTime, Utc}; use super::*; - use crate::{CipherRepromptType, LoginView}; #[test] fn test_try_from_folder_view() { @@ -141,7 +140,7 @@ mod tests { revision_date: "2024-01-30T17:55:36.150Z".parse().unwrap(), }; - let f: bitwarden_exporters::Folder = view.try_into().unwrap(); + let f: crate::Folder = view.try_into().unwrap(); assert_eq!( f.id, @@ -187,7 +186,7 @@ mod tests { revision_date: "2024-01-30T17:55:36.150Z".parse().unwrap(), }; - let cipher: bitwarden_exporters::Cipher = cipher_view.try_into().unwrap(); + let cipher: crate::Cipher = cipher_view.try_into().unwrap(); assert_eq!( cipher.id, @@ -209,7 +208,7 @@ mod tests { ); assert_eq!(cipher.deleted_date, None); - if let bitwarden_exporters::CipherType::Login(l) = cipher.r#type { + if let crate::CipherType::Login(l) = cipher.r#type { assert_eq!(l.username, Some("test_username".to_string())); assert_eq!(l.password, Some("test_password".to_string())); assert!(l.login_uris.is_empty()); diff --git a/crates/bitwarden-vault/Cargo.toml b/crates/bitwarden-vault/Cargo.toml index 379b23997..f14f090d9 100644 --- a/crates/bitwarden-vault/Cargo.toml +++ b/crates/bitwarden-vault/Cargo.toml @@ -25,7 +25,6 @@ base64 = ">=0.21.2, <0.23" bitwarden-api-api = { workspace = true } bitwarden-core = { workspace = true } bitwarden-crypto = { workspace = true } -bitwarden-exporters = { workspace = true } chrono = { version = ">=0.4.26, <0.5", default-features = false } rand = ">=0.8.5, <0.9" hmac = ">=0.12.1, <0.13" diff --git a/crates/bitwarden-vault/src/cipher/field.rs b/crates/bitwarden-vault/src/cipher/field.rs index 2141006af..6c826d4ba 100644 --- a/crates/bitwarden-vault/src/cipher/field.rs +++ b/crates/bitwarden-vault/src/cipher/field.rs @@ -35,11 +35,11 @@ pub struct Field { #[serde(rename_all = "camelCase", deny_unknown_fields)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] pub struct FieldView { - pub(crate) name: Option, - pub(crate) value: Option, - pub(crate) r#type: FieldType, + pub name: Option, + pub value: Option, + pub r#type: FieldType, - pub(crate) linked_id: Option, + pub linked_id: Option, } impl KeyEncryptable for FieldView { diff --git a/crates/bitwarden-vault/src/cipher/mod.rs b/crates/bitwarden-vault/src/cipher/mod.rs index 1b13ac743..67513d524 100644 --- a/crates/bitwarden-vault/src/cipher/mod.rs +++ b/crates/bitwarden-vault/src/cipher/mod.rs @@ -16,6 +16,6 @@ pub use cipher::{Cipher, CipherError, CipherListView, CipherRepromptType, Cipher pub use field::FieldView; pub use login::{ Fido2Credential, Fido2CredentialFullView, Fido2CredentialNewView, Fido2CredentialView, Login, - LoginView, + LoginUriView, LoginView, }; pub use secure_note::SecureNoteType; diff --git a/crates/bitwarden-vault/src/cipher/secure_note.rs b/crates/bitwarden-vault/src/cipher/secure_note.rs index 8ae39eb4d..2563160bb 100644 --- a/crates/bitwarden-vault/src/cipher/secure_note.rs +++ b/crates/bitwarden-vault/src/cipher/secure_note.rs @@ -25,7 +25,7 @@ pub struct SecureNote { #[serde(rename_all = "camelCase", deny_unknown_fields)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] pub struct SecureNoteView { - pub(crate) r#type: SecureNoteType, + pub r#type: SecureNoteType, } impl KeyEncryptable for SecureNoteView { diff --git a/crates/bitwarden-vault/src/lib.rs b/crates/bitwarden-vault/src/lib.rs index 4928f2766..1e5b5c5aa 100644 --- a/crates/bitwarden-vault/src/lib.rs +++ b/crates/bitwarden-vault/src/lib.rs @@ -17,4 +17,3 @@ mod totp; pub use totp::{generate_totp, TotpError, TotpResponse}; mod error; pub use error::VaultParseError; -mod exporters;