Skip to content

Commit f003d6c

Browse files
Add card brand to the CipherListViewType (#302)
## 🎟️ Tracking Related to [PM-22134](https://bitwarden.atlassian.net/browse/PM-22134) ## 📔 Objective Add the card brand to the `CipherListViewType` - This will be used to show the internal card icon when displayed in the list: <img width="600" alt="Screenshot 2025-06-09 at 8 50 43 AM" src="https://github.com/user-attachments/assets/f3cd7dc2-ff8f-4059-9607-8466e6f636e8" /> ## 🦮 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 [PM-22134]: https://bitwarden.atlassian.net/browse/PM-22134?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent d9586fc commit f003d6c

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ pub struct CardView {
3434
pub number: Option<String>,
3535
}
3636

37+
/// Minimal CardView only including the needed details for list views
38+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
39+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
40+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
41+
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
42+
pub struct CardListView {
43+
/// The brand of the card, e.g. Visa, Mastercard, etc.
44+
pub brand: Option<String>,
45+
}
46+
3747
#[allow(missing_docs)]
3848
#[derive(Serialize, Deserialize)]
3949
pub enum CardBrand {
@@ -69,6 +79,18 @@ impl Encryptable<KeyIds, SymmetricKeyId, Card> for CardView {
6979
}
7080
}
7181

82+
impl Decryptable<KeyIds, SymmetricKeyId, CardListView> for Card {
83+
fn decrypt(
84+
&self,
85+
ctx: &mut KeyStoreContext<KeyIds>,
86+
key: SymmetricKeyId,
87+
) -> Result<CardListView, CryptoError> {
88+
Ok(CardListView {
89+
brand: self.brand.decrypt(ctx, key).ok().flatten(),
90+
})
91+
}
92+
}
93+
7294
impl Decryptable<KeyIds, SymmetricKeyId, CardView> for Card {
7395
fn decrypt(
7496
&self,

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use wasm_bindgen::prelude::wasm_bindgen;
1919

2020
use super::{
2121
attachment, card,
22+
card::CardListView,
2223
cipher_permissions::CipherPermissions,
2324
field, identity,
2425
local_data::{LocalData, LocalDataView},
@@ -170,7 +171,7 @@ pub struct CipherView {
170171
pub enum CipherListViewType {
171172
Login(LoginListView),
172173
SecureNote,
173-
Card,
174+
Card(CardListView),
174175
Identity,
175176
SshKey,
176177
}
@@ -649,7 +650,13 @@ impl Decryptable<KeyIds, SymmetricKeyId, CipherListView> for Cipher {
649650
CipherListViewType::Login(login.decrypt(ctx, ciphers_key)?)
650651
}
651652
CipherType::SecureNote => CipherListViewType::SecureNote,
652-
CipherType::Card => CipherListViewType::Card,
653+
CipherType::Card => {
654+
let card = self
655+
.card
656+
.as_ref()
657+
.ok_or(CryptoError::MissingField("card"))?;
658+
CipherListViewType::Card(card.decrypt(ctx, ciphers_key)?)
659+
}
653660
CipherType::Identity => CipherListViewType::Identity,
654661
CipherType::SshKey => CipherListViewType::SshKey,
655662
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use attachment::{
1717
Attachment, AttachmentEncryptResult, AttachmentFile, AttachmentFileView, AttachmentView,
1818
};
1919
pub use attachment_client::{AttachmentsClient, DecryptFileError, EncryptFileError};
20-
pub use card::{CardBrand, CardView};
20+
pub use card::{CardBrand, CardListView, CardView};
2121
pub use cipher::{
2222
Cipher, CipherError, CipherListView, CipherListViewType, CipherRepromptType, CipherType,
2323
CipherView, EncryptionContext,

0 commit comments

Comments
 (0)