bitwarden_vault/cipher/
secure_note.rs1use bitwarden_api_api::models::CipherSecureNoteModel;
2use bitwarden_core::{
3 key_management::{KeyIds, SymmetricKeyId},
4 require,
5};
6use bitwarden_crypto::{CryptoError, Decryptable, Encryptable, KeyStoreContext};
7use serde::{Deserialize, Serialize};
8use serde_repr::{Deserialize_repr, Serialize_repr};
9#[cfg(feature = "wasm")]
10use tsify_next::Tsify;
11#[cfg(feature = "wasm")]
12use wasm_bindgen::prelude::wasm_bindgen;
13
14use crate::VaultParseError;
15
16#[derive(Clone, Copy, Serialize_repr, Deserialize_repr, Debug)]
17#[repr(u8)]
18#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
19#[cfg_attr(feature = "wasm", wasm_bindgen)]
20pub enum SecureNoteType {
21 Generic = 0,
22}
23
24#[derive(Clone, Serialize, Deserialize, Debug)]
25#[serde(rename_all = "camelCase", deny_unknown_fields)]
26#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
27#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
28pub struct SecureNote {
29 r#type: SecureNoteType,
30}
31
32#[derive(Clone, Serialize, Deserialize, Debug)]
33#[serde(rename_all = "camelCase", deny_unknown_fields)]
34#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
35#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
36pub struct SecureNoteView {
37 pub r#type: SecureNoteType,
38}
39
40impl Encryptable<KeyIds, SymmetricKeyId, SecureNote> for SecureNoteView {
41 fn encrypt(
42 &self,
43 _ctx: &mut KeyStoreContext<KeyIds>,
44 _key: SymmetricKeyId,
45 ) -> Result<SecureNote, CryptoError> {
46 Ok(SecureNote {
47 r#type: self.r#type,
48 })
49 }
50}
51
52impl Decryptable<KeyIds, SymmetricKeyId, SecureNoteView> for SecureNote {
53 fn decrypt(
54 &self,
55 _ctx: &mut KeyStoreContext<KeyIds>,
56 _key: SymmetricKeyId,
57 ) -> Result<SecureNoteView, CryptoError> {
58 Ok(SecureNoteView {
59 r#type: self.r#type,
60 })
61 }
62}
63
64impl TryFrom<CipherSecureNoteModel> for SecureNote {
65 type Error = VaultParseError;
66
67 fn try_from(model: CipherSecureNoteModel) -> Result<Self, Self::Error> {
68 Ok(Self {
69 r#type: require!(model.r#type).into(),
70 })
71 }
72}
73
74impl From<bitwarden_api_api::models::SecureNoteType> for SecureNoteType {
75 fn from(model: bitwarden_api_api::models::SecureNoteType) -> Self {
76 match model {
77 bitwarden_api_api::models::SecureNoteType::Generic => SecureNoteType::Generic,
78 }
79 }
80}