Skip to main content

bitwarden_vault/cipher/blob/conversions/
card.rs

1use super::{CardDataV1, CardView};
2
3impl_bidirectional_from!(
4    CardView,
5    CardDataV1,
6    [cardholder_name, exp_month, exp_year, code, brand, number,]
7);
8
9#[cfg(test)]
10mod tests {
11    use super::super::{CipherBlobV1, test_support::*};
12    use crate::cipher::{card::CardView, cipher::CipherType};
13
14    #[test]
15    fn test_card_cipher_round_trip() {
16        let original = crate::CipherView {
17            name: "My Card".to_string(),
18            notes: None,
19            r#type: CipherType::Card,
20            card: Some(CardView {
21                cardholder_name: Some("John Doe".to_string()),
22                exp_month: Some("12".to_string()),
23                exp_year: Some("2028".to_string()),
24                code: Some("123".to_string()),
25                brand: Some("Visa".to_string()),
26                number: Some("4111111111111111".to_string()),
27            }),
28            ..create_shell_cipher_view(CipherType::Card)
29        };
30
31        let blob = CipherBlobV1::from_cipher_view(&original).unwrap();
32        let mut restored = create_shell_cipher_view(CipherType::Card);
33        blob.apply_to_cipher_view(&mut restored).unwrap();
34
35        assert_eq!(restored.name, "My Card");
36        assert_eq!(restored.r#type, CipherType::Card);
37        let card = restored.card.unwrap();
38        assert_eq!(card.cardholder_name, Some("John Doe".to_string()));
39        assert_eq!(card.number, Some("4111111111111111".to_string()));
40        assert!(restored.login.is_none());
41    }
42}