Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/bitwarden-core/src/client/test_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use bitwarden_crypto::{EncString, Kdf};

use crate::{
key_management::crypto::{InitOrgCryptoRequest, InitUserCryptoMethod, InitUserCryptoRequest},
Client, UserId,
Client, ClientSettings, UserId,
};

impl Client {
pub async fn init_test_account(account: TestAccount) -> Self {
let client = Client::new(None);
pub async fn init_test_account(account: TestAccount, settings: Option<ClientSettings>) -> Self {
let client = Client::new(settings);

client.internal.load_flags(HashMap::from([(
"enableCipherKeyEncryption".to_owned(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ mod tests {
#[tokio::test]
async fn test_enroll_pin_envelope() {
// Initialize a test client with user crypto
let client = Client::init_test_account(test_bitwarden_com_account()).await;
let client = Client::init_test_account(test_bitwarden_com_account(), None).await;
let user_key_initial =
SymmetricCryptoKey::try_from(client.crypto().get_user_encryption_key().await.unwrap())
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ wasm = [
"bitwarden-collections/wasm",
"bitwarden-core/wasm",
"bitwarden-encoding/wasm",
"bitwarden-crypto/wasm",
"dep:tsify",
"dep:wasm-bindgen",
"dep:wasm-bindgen-futures"
Expand Down
13 changes: 13 additions & 0 deletions crates/bitwarden-vault/src/cipher/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ impl TryFrom<CipherCardModel> for Card {
}
}

impl From<Card> for bitwarden_api_api::models::CipherCardModel {
fn from(card: Card) -> Self {
Self {
cardholder_name: card.cardholder_name.map(|n| n.to_string()),
brand: card.brand.map(|b| b.to_string()),
number: card.number.map(|n| n.to_string()),
exp_month: card.exp_month.map(|m| m.to_string()),
exp_year: card.exp_year.map(|y| y.to_string()),
code: card.code.map(|c| c.to_string()),
}
}
}

impl CipherKind for Card {
fn decrypt_subtitle(
&self,
Expand Down
80 changes: 79 additions & 1 deletion crates/bitwarden-vault/src/cipher/cipher.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bitwarden_api_api::models::CipherDetailsResponseModel;
use bitwarden_api_api::models::{CipherDetailsResponseModel, CipherResponseModel};
use bitwarden_collections::collection::CollectionId;
use bitwarden_core::{
key_management::{KeyIds, SymmetricKeyId},
Expand Down Expand Up @@ -692,6 +692,15 @@ impl Decryptable<KeyIds, SymmetricKeyId, CipherListView> for Cipher {
}
}

#[cfg(feature = "wasm")]
impl wasm_bindgen::__rt::VectorIntoJsValue for CipherView {
fn vector_into_jsvalue(
vector: wasm_bindgen::__rt::std::boxed::Box<[Self]>,
) -> wasm_bindgen::JsValue {
wasm_bindgen::__rt::js_value_vector_into_jsvalue(vector)
}
}

impl IdentifyKey<SymmetricKeyId> for Cipher {
fn key_identifier(&self) -> SymmetricKeyId {
match self.organization_id {
Expand Down Expand Up @@ -793,6 +802,75 @@ impl From<bitwarden_api_api::models::CipherRepromptType> for CipherRepromptType
}
}

impl From<CipherType> for bitwarden_api_api::models::CipherType {
fn from(t: CipherType) -> Self {
match t {
CipherType::Login => bitwarden_api_api::models::CipherType::Login,
CipherType::SecureNote => bitwarden_api_api::models::CipherType::SecureNote,
CipherType::Card => bitwarden_api_api::models::CipherType::Card,
CipherType::Identity => bitwarden_api_api::models::CipherType::Identity,
CipherType::SshKey => bitwarden_api_api::models::CipherType::SSHKey,
}
}
}

impl From<CipherRepromptType> for bitwarden_api_api::models::CipherRepromptType {
fn from(t: CipherRepromptType) -> Self {
match t {
CipherRepromptType::None => bitwarden_api_api::models::CipherRepromptType::None,
CipherRepromptType::Password => bitwarden_api_api::models::CipherRepromptType::Password,
}
}
}

impl TryFrom<CipherResponseModel> for Cipher {
type Error = VaultParseError;

fn try_from(cipher: CipherResponseModel) -> Result<Self, Self::Error> {
Ok(Self {
id: cipher.id.map(CipherId::new),
organization_id: cipher.organization_id.map(OrganizationId::new),
folder_id: cipher.folder_id.map(FolderId::new),
collection_ids: vec![], // CipherResponseModel doesn't include collection_ids
name: require!(EncString::try_from_optional(cipher.name)?),
notes: EncString::try_from_optional(cipher.notes)?,
r#type: require!(cipher.r#type).into(),
login: cipher.login.map(|l| (*l).try_into()).transpose()?,
identity: cipher.identity.map(|i| (*i).try_into()).transpose()?,
card: cipher.card.map(|c| (*c).try_into()).transpose()?,
secure_note: cipher.secure_note.map(|s| (*s).try_into()).transpose()?,
ssh_key: cipher.ssh_key.map(|s| (*s).try_into()).transpose()?,
favorite: cipher.favorite.unwrap_or(false),
reprompt: cipher
.reprompt
.map(|r| r.into())
.unwrap_or(CipherRepromptType::None),
organization_use_totp: cipher.organization_use_totp.unwrap_or(false),
edit: cipher.edit.unwrap_or(false),
permissions: cipher.permissions.map(|p| (*p).try_into()).transpose()?,
view_password: cipher.view_password.unwrap_or(true),
local_data: None, // Not sent from server
attachments: cipher
.attachments
.map(|a| a.into_iter().map(|a| a.try_into()).collect())
.transpose()?,
fields: cipher
.fields
.map(|f| f.into_iter().map(|f| f.try_into()).collect())
.transpose()?,
password_history: cipher
.password_history
.map(|p| p.into_iter().map(|p| p.try_into()).collect())
.transpose()?,
creation_date: require!(cipher.creation_date).parse()?,
deleted_date: cipher.deleted_date.map(|d| d.parse()).transpose()?,
revision_date: require!(cipher.revision_date).parse()?,
key: EncString::try_from_optional(cipher.key)?,
archived_date: cipher.archived_date.map(|d| d.parse()).transpose()?,
})
}
}

#[cfg(test)]
mod tests {

Expand Down
Loading
Loading