Skip to main content

bitwarden_vault/cipher/
cipher_view_type.rs

1use serde::{Deserialize, Serialize};
2#[cfg(feature = "wasm")]
3use tsify::Tsify;
4
5use crate::{
6    BankAccountView, CardView, DriversLicenseView, IdentityView, LoginView, PassportView,
7    SecureNoteView, SshKeyView,
8};
9
10/// Represents the inner data of a cipher view.
11#[derive(Serialize, Deserialize, Debug, Clone)]
12#[serde(rename_all = "camelCase")]
13#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
14#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
15#[allow(missing_docs, clippy::large_enum_variant)]
16pub enum CipherViewType {
17    Login(LoginView),
18    Card(CardView),
19    Identity(IdentityView),
20    SecureNote(SecureNoteView),
21    SshKey(SshKeyView),
22    BankAccount(BankAccountView),
23    Passport(PassportView),
24    DriversLicense(DriversLicenseView),
25}
26
27impl CipherViewType {
28    /// Returns the corresponding [crate::CipherType] for this view type.
29    pub fn get_cipher_type(&self) -> crate::CipherType {
30        match self {
31            CipherViewType::Login(_) => crate::CipherType::Login,
32            CipherViewType::Card(_) => crate::CipherType::Card,
33            CipherViewType::Identity(_) => crate::CipherType::Identity,
34            CipherViewType::SecureNote(_) => crate::CipherType::SecureNote,
35            CipherViewType::SshKey(_) => crate::CipherType::SshKey,
36            CipherViewType::BankAccount(_) => crate::CipherType::BankAccount,
37            CipherViewType::Passport(_) => crate::CipherType::Passport,
38            CipherViewType::DriversLicense(_) => crate::CipherType::DriversLicense,
39        }
40    }
41}
42
43#[allow(unused)]
44impl CipherViewType {
45    pub(crate) fn as_login_view_mut(&mut self) -> Option<&mut LoginView> {
46        match self {
47            CipherViewType::Login(l) => Some(l),
48            _ => None,
49        }
50    }
51
52    pub(crate) fn as_card_view_mut(&mut self) -> Option<&mut CardView> {
53        match self {
54            CipherViewType::Card(c) => Some(c),
55            _ => None,
56        }
57    }
58
59    pub(crate) fn as_identity_view_mut(&mut self) -> Option<&mut IdentityView> {
60        match self {
61            CipherViewType::Identity(i) => Some(i),
62            _ => None,
63        }
64    }
65
66    pub(crate) fn as_secure_note_view_mut(&mut self) -> Option<&mut SecureNoteView> {
67        match self {
68            CipherViewType::SecureNote(s) => Some(s),
69            _ => None,
70        }
71    }
72
73    pub(crate) fn as_ssh_key_view_mut(&mut self) -> Option<&mut SshKeyView> {
74        match self {
75            CipherViewType::SshKey(s) => Some(s),
76            _ => None,
77        }
78    }
79
80    pub(crate) fn as_bank_account_view_mut(&mut self) -> Option<&mut BankAccountView> {
81        match self {
82            CipherViewType::BankAccount(b) => Some(b),
83            _ => None,
84        }
85    }
86
87    pub(crate) fn as_drivers_license_view_mut(&mut self) -> Option<&mut DriversLicenseView> {
88        match self {
89            CipherViewType::DriversLicense(d) => Some(d),
90            _ => None,
91        }
92    }
93
94    pub(crate) fn as_passport_view_mut(&mut self) -> Option<&mut PassportView> {
95        match self {
96            CipherViewType::Passport(p) => Some(p),
97            _ => None,
98        }
99    }
100
101    pub(crate) fn as_login_view(&self) -> Option<&LoginView> {
102        match self {
103            CipherViewType::Login(l) => Some(l),
104            _ => None,
105        }
106    }
107
108    pub(crate) fn as_card_view(&self) -> Option<&CardView> {
109        match self {
110            CipherViewType::Card(c) => Some(c),
111            _ => None,
112        }
113    }
114
115    pub(crate) fn as_identity_view(&self) -> Option<&IdentityView> {
116        match self {
117            CipherViewType::Identity(i) => Some(i),
118            _ => None,
119        }
120    }
121
122    pub(crate) fn as_secure_note_view(&self) -> Option<&SecureNoteView> {
123        match self {
124            CipherViewType::SecureNote(s) => Some(s),
125            _ => None,
126        }
127    }
128
129    pub(crate) fn as_ssh_key_view(&self) -> Option<&SshKeyView> {
130        match self {
131            CipherViewType::SshKey(s) => Some(s),
132            _ => None,
133        }
134    }
135
136    pub(crate) fn as_bank_account_view(&self) -> Option<&BankAccountView> {
137        match self {
138            CipherViewType::BankAccount(b) => Some(b),
139            _ => None,
140        }
141    }
142
143    pub(crate) fn as_drivers_license_view(&self) -> Option<&DriversLicenseView> {
144        match self {
145            CipherViewType::DriversLicense(d) => Some(d),
146            _ => None,
147        }
148    }
149
150    pub(crate) fn as_passport_view(&self) -> Option<&PassportView> {
151        match self {
152            CipherViewType::Passport(p) => Some(p),
153            _ => None,
154        }
155    }
156}