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