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
This commit is contained in:
Sosthène Guédon
2024-10-07 13:48:37 +02:00
committed by sosthene-nitrokey
parent 6b3ce6928e
commit c48b2b29df
+7 -1
View File
@@ -806,7 +806,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<V>(self, visitor: V) -> Result<V::Value>