Skip to content

Commit cb0ac94

Browse files
authored
[PM-25657] Add missing SSH key and permissions fields to cipher conversion (#434)
## 🎟️ Tracking https://bitwarden.atlassian.net/browse/PM-25657 <!-- Paste the link to the Jira or GitHub issue or otherwise describe / point to where this change is coming from. --> ## 📔 Objective <!-- Describe what the purpose of this PR is, for example what bug you're fixing or new feature you're adding. --> ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes
1 parent a321999 commit cb0ac94

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

crates/bitwarden-vault/src/cipher/cipher.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,17 +736,15 @@ impl TryFrom<CipherDetailsResponseModel> for Cipher {
736736
identity: cipher.identity.map(|i| (*i).try_into()).transpose()?,
737737
card: cipher.card.map(|c| (*c).try_into()).transpose()?,
738738
secure_note: cipher.secure_note.map(|s| (*s).try_into()).transpose()?,
739-
// TODO: add ssh_key when api bindings have been updated
740-
ssh_key: None,
739+
ssh_key: cipher.ssh_key.map(|s| (*s).try_into()).transpose()?,
741740
favorite: cipher.favorite.unwrap_or(false),
742741
reprompt: cipher
743742
.reprompt
744743
.map(|r| r.into())
745744
.unwrap_or(CipherRepromptType::None),
746745
organization_use_totp: cipher.organization_use_totp.unwrap_or(true),
747746
edit: cipher.edit.unwrap_or(true),
748-
// TODO: add permissions when api bindings have been updated
749-
permissions: None,
747+
permissions: cipher.permissions.map(|p| (*p).try_into()).transpose()?,
750748
view_password: cipher.view_password.unwrap_or(true),
751749
local_data: None, // Not sent from server
752750
attachments: cipher

crates/bitwarden-vault/src/cipher/cipher_permissions.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
use bitwarden_api_api::models::CipherPermissionsResponseModel;
2+
use bitwarden_core::require;
13
use serde::{Deserialize, Serialize};
24
#[cfg(feature = "wasm")]
35
use tsify::Tsify;
46

7+
use crate::VaultParseError;
8+
59
#[derive(Serialize, Copy, Deserialize, Debug, Clone, PartialEq)]
610
#[serde(rename_all = "camelCase", deny_unknown_fields)]
711
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
@@ -10,3 +14,14 @@ pub struct CipherPermissions {
1014
pub delete: bool,
1115
pub restore: bool,
1216
}
17+
18+
impl TryFrom<CipherPermissionsResponseModel> for CipherPermissions {
19+
type Error = VaultParseError;
20+
21+
fn try_from(permissions: CipherPermissionsResponseModel) -> Result<Self, Self::Error> {
22+
Ok(Self {
23+
delete: require!(permissions.delete),
24+
restore: require!(permissions.restore),
25+
})
26+
}
27+
}

crates/bitwarden-vault/src/cipher/ssh_key.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use bitwarden_core::key_management::{KeyIds, SymmetricKeyId};
1+
use bitwarden_api_api::models::CipherSshKeyModel;
2+
use bitwarden_core::{
3+
key_management::{KeyIds, SymmetricKeyId},
4+
require,
5+
};
26
use bitwarden_crypto::{
37
CompositeEncryptable, CryptoError, Decryptable, EncString, KeyStoreContext,
48
PrimitiveEncryptable,
@@ -8,7 +12,7 @@ use serde::{Deserialize, Serialize};
812
use tsify::Tsify;
913

1014
use super::cipher::CipherKind;
11-
use crate::{cipher::cipher::CopyableCipherFields, Cipher};
15+
use crate::{cipher::cipher::CopyableCipherFields, Cipher, VaultParseError};
1216

1317
#[derive(Serialize, Deserialize, Debug, Clone)]
1418
#[serde(rename_all = "camelCase", deny_unknown_fields)]
@@ -79,6 +83,18 @@ impl CipherKind for SshKey {
7983
}
8084
}
8185

86+
impl TryFrom<CipherSshKeyModel> for SshKey {
87+
type Error = VaultParseError;
88+
89+
fn try_from(ssh_key: CipherSshKeyModel) -> Result<Self, Self::Error> {
90+
Ok(Self {
91+
private_key: require!(EncString::try_from_optional(ssh_key.private_key)?),
92+
public_key: require!(EncString::try_from_optional(ssh_key.public_key)?),
93+
fingerprint: require!(EncString::try_from_optional(ssh_key.key_fingerprint)?),
94+
})
95+
}
96+
}
97+
8298
#[cfg(test)]
8399
mod tests {
84100
use bitwarden_core::key_management::create_test_crypto_with_user_key;

0 commit comments

Comments
 (0)