bitwarden_importers/importers/onepassword/access/model.rs
1//! What a download yields: vaults holding items, each item still in its decrypted 1Password shape.
2//!
3//! Mapping these onto Bitwarden ciphers is the importer's job and happens elsewhere.
4
5use super::wire::{VaultItemDetails, VaultItemOverview};
6
7/// A decrypted vault with its items.
8pub struct Vault {
9 /// The vault's 1Password uuid.
10 pub id: String,
11 /// The vault's display name.
12 pub name: String,
13 /// The vault's description, empty when unset.
14 pub description: String,
15 /// Every item in the vault except the trashed ones.
16 pub items: Vec<Item>,
17}
18
19/// A decrypted item: its identity plus both payloads exactly as 1Password sends them.
20pub struct Item {
21 /// The item's 1Password uuid.
22 pub id: String,
23 /// The item's category, derived from its template id.
24 pub category: ItemCategory,
25 /// The decrypted `encOverview`: title, subtitle, websites, tags.
26 pub overview: VaultItemOverview,
27 /// The decrypted `encDetails`: login fields, sections, note, password history.
28 pub details: VaultItemDetails,
29}
30
31/// The kind of a vault item, mapped from its template id. The ids are 1Password's standard
32/// category template UUIDs; an unrecognized id is preserved as [`ItemCategory::Unknown`] so nothing
33/// is lost.
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub enum ItemCategory {
36 /// Template `001`.
37 Login,
38 /// Template `002`.
39 CreditCard,
40 /// Template `003`.
41 SecureNote,
42 /// Template `004`.
43 Identity,
44 /// Template `005`.
45 Password,
46 /// Template `006`.
47 Document,
48 /// Template `100`.
49 SoftwareLicense,
50 /// Template `101`.
51 BankAccount,
52 /// Template `102`.
53 Database,
54 /// Template `103`.
55 DriverLicense,
56 /// Template `104`.
57 OutdoorLicense,
58 /// Template `105`.
59 Membership,
60 /// Template `106`.
61 Passport,
62 /// Template `107`.
63 RewardProgram,
64 /// Template `108`.
65 SocialSecurityNumber,
66 /// Template `109`.
67 WirelessRouter,
68 /// Template `110`.
69 Server,
70 /// Template `111`.
71 EmailAccount,
72 /// Template `112`.
73 ApiCredential,
74 /// Template `113`.
75 MedicalRecord,
76 /// Template `114`.
77 SshKey,
78 /// A template id this crate does not know, kept verbatim.
79 Unknown(String),
80}
81
82impl ItemCategory {
83 /// Maps a 1Password template id to a category. Extends the `TemplateId` handling in
84 /// `Client.ConvertVaultItem` to the full standard template set.
85 pub(super) fn from_template_id(id: &str) -> ItemCategory {
86 match id {
87 "001" => ItemCategory::Login,
88 "002" => ItemCategory::CreditCard,
89 "003" => ItemCategory::SecureNote,
90 "004" => ItemCategory::Identity,
91 "005" => ItemCategory::Password,
92 "006" => ItemCategory::Document,
93 "100" => ItemCategory::SoftwareLicense,
94 "101" => ItemCategory::BankAccount,
95 "102" => ItemCategory::Database,
96 "103" => ItemCategory::DriverLicense,
97 "104" => ItemCategory::OutdoorLicense,
98 "105" => ItemCategory::Membership,
99 "106" => ItemCategory::Passport,
100 "107" => ItemCategory::RewardProgram,
101 "108" => ItemCategory::SocialSecurityNumber,
102 "109" => ItemCategory::WirelessRouter,
103 "110" => ItemCategory::Server,
104 "111" => ItemCategory::EmailAccount,
105 "112" => ItemCategory::ApiCredential,
106 "113" => ItemCategory::MedicalRecord,
107 "114" => ItemCategory::SshKey,
108 other => ItemCategory::Unknown(other.to_string()),
109 }
110 }
111}