Skip to content

Commit

Permalink
deserialize_identifier: add support for all types expected by serde
Browse files Browse the repository at this point in the history
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 Nitrokey/fido-authenticator#57,
which needs compatibility with both the str variant and the index variant
  • Loading branch information
sosthene-nitrokey committed Oct 2, 2024
1 parent da58de3 commit a0d0296
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<V>(self, visitor: V) -> Result<V::Value>
Expand Down

0 comments on commit a0d0296

Please sign in to comment.