bitwarden_vault/cipher/
cipher_view_type.rs1use serde::{Deserialize, Serialize};
2#[cfg(feature = "wasm")]
3use tsify::Tsify;
4
5use crate::{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}
20
21impl CipherViewType {
22 pub fn get_cipher_type(&self) -> crate::CipherType {
24 match self {
25 CipherViewType::Login(_) => crate::CipherType::Login,
26 CipherViewType::Card(_) => crate::CipherType::Card,
27 CipherViewType::Identity(_) => crate::CipherType::Identity,
28 CipherViewType::SecureNote(_) => crate::CipherType::SecureNote,
29 CipherViewType::SshKey(_) => crate::CipherType::SshKey,
30 }
31 }
32}
33
34#[allow(unused)]
35impl CipherViewType {
36 pub(crate) fn as_login_view_mut(&mut self) -> Option<&mut LoginView> {
37 match self {
38 CipherViewType::Login(l) => Some(l),
39 _ => None,
40 }
41 }
42
43 pub(crate) fn as_card_view_mut(&mut self) -> Option<&mut CardView> {
44 match self {
45 CipherViewType::Card(c) => Some(c),
46 _ => None,
47 }
48 }
49
50 pub(crate) fn as_identity_view_mut(&mut self) -> Option<&mut IdentityView> {
51 match self {
52 CipherViewType::Identity(i) => Some(i),
53 _ => None,
54 }
55 }
56
57 pub(crate) fn as_secure_note_view_mut(&mut self) -> Option<&mut SecureNoteView> {
58 match self {
59 CipherViewType::SecureNote(s) => Some(s),
60 _ => None,
61 }
62 }
63
64 pub(crate) fn as_ssh_key_view_mut(&mut self) -> Option<&mut SshKeyView> {
65 match self {
66 CipherViewType::SshKey(s) => Some(s),
67 _ => None,
68 }
69 }
70 pub(crate) fn as_login_view(&self) -> Option<&LoginView> {
71 match self {
72 CipherViewType::Login(l) => Some(l),
73 _ => None,
74 }
75 }
76
77 pub(crate) fn as_card_view(&self) -> Option<&CardView> {
78 match self {
79 CipherViewType::Card(c) => Some(c),
80 _ => None,
81 }
82 }
83
84 pub(crate) fn as_identity_view(&self) -> Option<&IdentityView> {
85 match self {
86 CipherViewType::Identity(i) => Some(i),
87 _ => None,
88 }
89 }
90
91 pub(crate) fn as_secure_note_view(&self) -> Option<&SecureNoteView> {
92 match self {
93 CipherViewType::SecureNote(s) => Some(s),
94 _ => None,
95 }
96 }
97
98 pub(crate) fn as_ssh_key_view(&self) -> Option<&SshKeyView> {
99 match self {
100 CipherViewType::SshKey(s) => Some(s),
101 _ => None,
102 }
103 }
104}