From 0d51c02683b449f05ba41986155297a9c043882d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Mon, 12 Feb 2024 16:26:27 +0100 Subject: [PATCH] deserialize_identifier: add support for all types expected by serde The default serde deserialize derive accepts 3 types for identifiers: - The name of the field as `str` - The name of the field as ascii bytes - The index of the field as u64 This PR changes deserialize_identifier to have compatibility with all of these This is necessary for https://github.com/Nitrokey/fido-authenticator/issues/57, which needs compatibility with both the str variant and the index variant --- src/de.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/de.rs b/src/de.rs index 092eb399..fa1e6569 100644 --- a/src/de.rs +++ b/src/de.rs @@ -803,7 +803,13 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { where V: Visitor<'de>, { - self.deserialize_str(visitor) + let major = self.peek_major()?; + match major { + MAJOR_STR => self.deserialize_str(visitor), + MAJOR_POSINT => self.deserialize_u64(visitor), + MAJOR_BYTES => self.deserialize_bytes(visitor), + _ => Err(Error::DeserializeBadMajor), + } } fn deserialize_ignored_any(self, visitor: V) -> Result