bitwarden_vault/cipher/blob/conversions/
passport.rs1use super::{PassportDataV1, PassportView};
2
3impl_bidirectional_from!(
4 PassportView,
5 PassportDataV1,
6 [
7 surname,
8 given_name,
9 date_of_birth,
10 sex,
11 birth_place,
12 nationality,
13 issuing_country,
14 passport_number,
15 passport_type,
16 national_identification_number,
17 issuing_authority,
18 issue_date,
19 expiration_date,
20 ]
21);
22
23#[cfg(test)]
24mod tests {
25 use super::super::{CipherBlobV1, test_support::*};
26 use crate::cipher::{cipher::CipherType, passport::PassportView};
27
28 #[test]
29 fn test_passport_cipher_round_trip() {
30 let (key_store, key_id) = create_test_key_store();
31 let mut ctx = key_store.context_mut();
32
33 let original = crate::CipherView {
34 name: "My Passport".to_string(),
35 notes: None,
36 r#type: CipherType::Passport,
37 passport: Some(PassportView {
38 surname: Some("Doe".to_string()),
39 given_name: Some("Jane".to_string()),
40 date_of_birth: Some("1990-01-01".to_string()),
41 sex: Some("F".to_string()),
42 birth_place: Some("New York".to_string()),
43 nationality: Some("American".to_string()),
44 issuing_country: Some("US".to_string()),
45 passport_number: Some("P12345678".to_string()),
46 passport_type: Some("P".to_string()),
47 national_identification_number: Some("123-45-6789".to_string()),
48 issuing_authority: Some("US State Department".to_string()),
49 issue_date: Some("2020-01-01".to_string()),
50 expiration_date: Some("2030-01-01".to_string()),
51 }),
52 ..create_shell_cipher_view(CipherType::Passport)
53 };
54
55 let blob = CipherBlobV1::from_cipher_view(&original, &mut ctx, key_id).unwrap();
56 let mut restored = create_shell_cipher_view(CipherType::Passport);
57 blob.apply_to_cipher_view(&mut restored, &mut ctx, key_id)
58 .unwrap();
59
60 assert_eq!(restored.name, "My Passport");
61 assert_eq!(restored.r#type, CipherType::Passport);
62 let passport = restored.passport.unwrap();
63 assert_eq!(passport.surname, Some("Doe".to_string()));
64 assert_eq!(passport.passport_number, Some("P12345678".to_string()));
65 assert!(restored.login.is_none());
66 }
67}