Skip to content

Commit 8ea5654

Browse files
authored
[PM-27214]Accept SecureNote with Type 1 and set to 0 (#521)
Changes allow for Cipher Notes to have Type:1 and setting them to 0
1 parent 07e1998 commit 8ea5654

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

crates/bitwarden-vault/src/cipher/secure_note.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use bitwarden_core::{
44
require,
55
};
66
use bitwarden_crypto::{CompositeEncryptable, CryptoError, Decryptable, KeyStoreContext};
7-
use serde::{Deserialize, Serialize};
8-
use serde_repr::{Deserialize_repr, Serialize_repr};
7+
use serde::{Deserialize, Deserializer, Serialize};
8+
use serde_repr::Serialize_repr;
99
#[cfg(feature = "wasm")]
1010
use tsify::Tsify;
1111
#[cfg(feature = "wasm")]
@@ -17,7 +17,7 @@ use crate::{
1717
};
1818

1919
#[allow(missing_docs)]
20-
#[derive(Clone, Copy, Serialize_repr, Deserialize_repr, Debug)]
20+
#[derive(Clone, Copy, Serialize_repr, Debug)]
2121
#[repr(u8)]
2222
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
2323
#[cfg_attr(feature = "wasm", wasm_bindgen)]
@@ -33,6 +33,24 @@ pub struct SecureNote {
3333
r#type: SecureNoteType,
3434
}
3535

36+
/// Use the custom deserializer for SecureNoteType
37+
/// Older notes may have a Type greater than 0. If so set them to Generic
38+
impl<'de> Deserialize<'de> for SecureNoteType {
39+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
40+
where
41+
D: Deserializer<'de>,
42+
{
43+
match u8::deserialize(deserializer) {
44+
Ok(0) => Ok(SecureNoteType::Generic),
45+
Ok(_) => {
46+
// Any unknown type (like type 1) defaults to Generic
47+
Ok(SecureNoteType::Generic)
48+
}
49+
Err(_) => Ok(SecureNoteType::Generic),
50+
}
51+
}
52+
}
53+
3654
#[allow(missing_docs)]
3755
#[derive(Clone, Serialize, Deserialize, Debug)]
3856
#[serde(rename_all = "camelCase", deny_unknown_fields)]

0 commit comments

Comments
 (0)