Skip to content

Commit da0c62c

Browse files
committed
update secure note to accept a type value of 1 and set it to generic
1 parent 2a00b72 commit da0c62c

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

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

Lines changed: 22 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,25 @@ 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+
// This allows the SDK to handle future secure note types gracefully
48+
Ok(SecureNoteType::Generic)
49+
}
50+
Err(_) => Ok(SecureNoteType::Generic),
51+
}
52+
}
53+
}
54+
3655
#[allow(missing_docs)]
3756
#[derive(Clone, Serialize, Deserialize, Debug)]
3857
#[serde(rename_all = "camelCase", deny_unknown_fields)]

0 commit comments

Comments
 (0)