From 387cb26dd5b03470a317aade5b0b709d67709477 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 d43fba0e..afd5f0b9 100644 --- a/src/de.rs +++ b/src/de.rs @@ -682,7 +682,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