bitwarden_vault/cipher/
cipher_view_type.rs1use serde::{Deserialize, Serialize};
2#[cfg(feature = "wasm")]
3use tsify::Tsify;
4
5use crate::{BankAccountView, CardView, IdentityView, LoginView, SecureNoteView, SshKeyView};
6
7#[derive(Serialize, Deserialize, Debug, Clone)]
9#[serde(rename_all = "camelCase")]
10#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
11#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
12#[allow(missing_docs, clippy::large_enum_variant)]
13pub enum CipherViewType {
14 Login(LoginView),
15 Card(CardView),
16 Identity(IdentityView),
17 SecureNote(SecureNoteView),
18 SshKey(SshKeyView),
19 BankAccount(BankAccountView),
20}
21
22impl CipherViewType {
23 pub fn get_cipher_type(&self) -> crate::CipherType {
25 match self {
26 CipherViewType::Login(_) => crate::CipherType::Login,
27 CipherViewType::Card(_) => crate::CipherType::Card,
28 CipherViewType::Identity(_) => crate::CipherType::Identity,
29 CipherViewType::SecureNote(_) => crate::CipherType::SecureNote,
30 CipherViewType::SshKey(_) => crate::CipherType::SshKey,
31 CipherViewType::BankAccount(_) => crate::CipherType::BankAccount,
32 }
33 }
34}
35
36#[allow(unused)]
37impl CipherViewType {
38 pub(crate) fn as_login_view_mut(&mut self) -> Option<&mut LoginView> {
39 match self {
40 CipherViewType::Login(l) => Some(l),
41 _ => None,
42 }
43 }
44
45 pub(crate) fn as_card_view_mut(&mut self) -> Option<&mut CardView> {
46 match self {
47 CipherViewType::Card(c) => Some(c),
48 _ => None,
49 }
50 }
51
52 pub(crate) fn as_identity_view_mut(&mut self) -> Option<&mut IdentityView> {
53 match self {
54 CipherViewType::Identity(i) => Some(i),
55 _ => None,
56 }
57 }
58
59 pub(crate) fn as_secure_note_view_mut(&mut self) -> Option<&mut SecureNoteView> {
60 match self {
61 CipherViewType::SecureNote(s) => Some(s),
62 _ => None,
63 }
64 }
65
66 pub(crate) fn as_ssh_key_view_mut(&mut self) -> Option<&mut SshKeyView> {
67 match self {
68 CipherViewType::SshKey(s) => Some(s),
69 _ => None,
70 }
71 }
72
73 pub(crate) fn as_bank_account_view_mut(&mut self) -> Option<&mut BankAccountView> {
74 match self {
75 CipherViewType::BankAccount(b) => Some(b),
76 _ => None,
77 }
78 }
79
80 pub(crate) fn as_login_view(&self) -> Option<&LoginView> {
81 match self {
82 CipherViewType::Login(l) => Some(l),
83 _ => None,
84 }
85 }
86
87 pub(crate) fn as_card_view(&self) -> Option<&CardView> {
88 match self {
89 CipherViewType::Card(c) => Some(c),
90 _ => None,
91 }
92 }
93
94 pub(crate) fn as_identity_view(&self) -> Option<&IdentityView> {
95 match self {
96 CipherViewType::Identity(i) => Some(i),
97 _ => None,
98 }
99 }
100
101 pub(crate) fn as_secure_note_view(&self) -> Option<&SecureNoteView> {
102 match self {
103 CipherViewType::SecureNote(s) => Some(s),
104 _ => None,
105 }
106 }
107
108 pub(crate) fn as_ssh_key_view(&self) -> Option<&SshKeyView> {
109 match self {
110 CipherViewType::SshKey(s) => Some(s),
111 _ => None,
112 }
113 }
114
115 pub(crate) fn as_bank_account_view(&self) -> Option<&BankAccountView> {
116 match self {
117 CipherViewType::BankAccount(b) => Some(b),
118 _ => None,
119 }
120 }
121}