From ae3d21349301bbdf97a14ce26950dad4b422482f Mon Sep 17 00:00:00 2001 From: gbubemismith Date: Wed, 10 Sep 2025 17:43:10 -0400 Subject: [PATCH] Added missing fields to cipher --- crates/bitwarden-vault/src/cipher/cipher.rs | 6 ++---- .../src/cipher/cipher_permissions.rs | 15 ++++++++++++++ crates/bitwarden-vault/src/cipher/ssh_key.rs | 20 +++++++++++++++++-- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/crates/bitwarden-vault/src/cipher/cipher.rs b/crates/bitwarden-vault/src/cipher/cipher.rs index 820fd3463..a55a94911 100644 --- a/crates/bitwarden-vault/src/cipher/cipher.rs +++ b/crates/bitwarden-vault/src/cipher/cipher.rs @@ -736,8 +736,7 @@ impl TryFrom for Cipher { 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()?, - // TODO: add ssh_key when api bindings have been updated - ssh_key: None, + ssh_key: cipher.ssh_key.map(|s| (*s).try_into()).transpose()?, favorite: cipher.favorite.unwrap_or(false), reprompt: cipher .reprompt @@ -745,8 +744,7 @@ impl TryFrom for Cipher { .unwrap_or(CipherRepromptType::None), organization_use_totp: cipher.organization_use_totp.unwrap_or(true), edit: cipher.edit.unwrap_or(true), - // TODO: add permissions when api bindings have been updated - permissions: None, + 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 diff --git a/crates/bitwarden-vault/src/cipher/cipher_permissions.rs b/crates/bitwarden-vault/src/cipher/cipher_permissions.rs index 710987c6a..328513414 100644 --- a/crates/bitwarden-vault/src/cipher/cipher_permissions.rs +++ b/crates/bitwarden-vault/src/cipher/cipher_permissions.rs @@ -1,7 +1,11 @@ +use bitwarden_api_api::models::CipherPermissionsResponseModel; +use bitwarden_core::require; use serde::{Deserialize, Serialize}; #[cfg(feature = "wasm")] use tsify::Tsify; +use crate::VaultParseError; + #[derive(Serialize, Copy, Deserialize, Debug, Clone, PartialEq)] #[serde(rename_all = "camelCase", deny_unknown_fields)] #[cfg_attr(feature = "uniffi", derive(uniffi::Record))] @@ -10,3 +14,14 @@ pub struct CipherPermissions { pub delete: bool, pub restore: bool, } + +impl TryFrom for CipherPermissions { + type Error = VaultParseError; + + fn try_from(permissions: CipherPermissionsResponseModel) -> Result { + Ok(Self { + delete: require!(permissions.delete), + restore: require!(permissions.restore), + }) + } +} diff --git a/crates/bitwarden-vault/src/cipher/ssh_key.rs b/crates/bitwarden-vault/src/cipher/ssh_key.rs index 137edca43..e56da0033 100644 --- a/crates/bitwarden-vault/src/cipher/ssh_key.rs +++ b/crates/bitwarden-vault/src/cipher/ssh_key.rs @@ -1,4 +1,8 @@ -use bitwarden_core::key_management::{KeyIds, SymmetricKeyId}; +use bitwarden_api_api::models::CipherSshKeyModel; +use bitwarden_core::{ + key_management::{KeyIds, SymmetricKeyId}, + require, +}; use bitwarden_crypto::{ CompositeEncryptable, CryptoError, Decryptable, EncString, KeyStoreContext, PrimitiveEncryptable, @@ -8,7 +12,7 @@ use serde::{Deserialize, Serialize}; use tsify::Tsify; use super::cipher::CipherKind; -use crate::{cipher::cipher::CopyableCipherFields, Cipher}; +use crate::{cipher::cipher::CopyableCipherFields, Cipher, VaultParseError}; #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(rename_all = "camelCase", deny_unknown_fields)] @@ -79,6 +83,18 @@ impl CipherKind for SshKey { } } +impl TryFrom for SshKey { + type Error = VaultParseError; + + fn try_from(ssh_key: CipherSshKeyModel) -> Result { + Ok(Self { + private_key: require!(EncString::try_from_optional(ssh_key.private_key)?), + public_key: require!(EncString::try_from_optional(ssh_key.public_key)?), + fingerprint: require!(EncString::try_from_optional(ssh_key.key_fingerprint)?), + }) + } +} + #[cfg(test)] mod tests { use bitwarden_core::key_management::create_test_crypto_with_user_key;