Skip to content

Commit

Permalink
Flip the dependency between exporters and vault (#833)
Browse files Browse the repository at this point in the history
In preparation for #798 we need to flip the relationship between vault
and exporters. Due to exporters in the future getting a
`client_exporters` which means they need to be able to access the vault
models to properly model it.
  • Loading branch information
Hinton authored Jun 11, 2024
1 parent 47f4b1c commit 3fc7fd2
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/bitwarden-exporters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-exporters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<FolderView> for bitwarden_exporters::Folder {
impl TryFrom<FolderView> for crate::Folder {
type Error = MissingFieldError;

fn try_from(value: FolderView) -> Result<Self, Self::Error> {
Expand All @@ -13,14 +14,14 @@ impl TryFrom<FolderView> for bitwarden_exporters::Folder {
}
}

impl TryFrom<CipherView> for bitwarden_exporters::Cipher {
impl TryFrom<CipherView> for crate::Cipher {
type Error = MissingFieldError;

fn try_from(value: CipherView) -> Result<Self, Self::Error> {
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
Expand All @@ -32,18 +33,16 @@ impl TryFrom<CipherView> 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,
Expand All @@ -54,7 +53,7 @@ impl TryFrom<CipherView> 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,
Expand Down Expand Up @@ -98,7 +97,7 @@ impl TryFrom<CipherView> for bitwarden_exporters::Cipher {
}
}

impl From<FieldView> for bitwarden_exporters::Field {
impl From<FieldView> for crate::Field {
fn from(value: FieldView) -> Self {
Self {
name: value.name,
Expand All @@ -109,7 +108,7 @@ impl From<FieldView> for bitwarden_exporters::Field {
}
}

impl From<LoginUriView> for bitwarden_exporters::LoginUri {
impl From<LoginUriView> for crate::LoginUri {
fn from(value: LoginUriView) -> Self {
Self {
r#match: value.r#match.map(|v| v as u8),
Expand All @@ -118,20 +117,20 @@ impl From<LoginUriView> for bitwarden_exporters::LoginUri {
}
}

impl From<SecureNoteType> for bitwarden_exporters::SecureNoteType {
impl From<SecureNoteType> 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() {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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());
Expand Down
1 change: 0 additions & 1 deletion crates/bitwarden-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions crates/bitwarden-vault/src/cipher/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub(crate) value: Option<String>,
pub(crate) r#type: FieldType,
pub name: Option<String>,
pub value: Option<String>,
pub r#type: FieldType,

pub(crate) linked_id: Option<LinkedIdType>,
pub linked_id: Option<LinkedIdType>,
}

impl KeyEncryptable<SymmetricCryptoKey, Field> for FieldView {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-vault/src/cipher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion crates/bitwarden-vault/src/cipher/secure_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SymmetricCryptoKey, SecureNote> for SecureNoteView {
Expand Down
1 change: 0 additions & 1 deletion crates/bitwarden-vault/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ mod totp;
pub use totp::{generate_totp, TotpError, TotpResponse};
mod error;
pub use error::VaultParseError;
mod exporters;

0 comments on commit 3fc7fd2

Please sign in to comment.