diff --git a/crates/ctap2-proto/src/authenticator/client_pin/mod.rs b/crates/ctap2-proto/src/authenticator/client_pin/mod.rs index 41694e8..22b9815 100644 --- a/crates/ctap2-proto/src/authenticator/client_pin/mod.rs +++ b/crates/ctap2-proto/src/authenticator/client_pin/mod.rs @@ -1,6 +1,8 @@ use bounded_integer::BoundedUsize; use std::collections::BTreeSet; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] pub enum AuthProtocolVersion { @@ -8,6 +10,42 @@ pub enum AuthProtocolVersion { Two, } +// workaround until is merged +// PR: ( Integer/boolean tags for internally/adjacently tagged enums #2056 ) +#[cfg(feature = "serde")] +impl Serialize for AuthProtocolVersion { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + serializer.serialize_u8(match self { + AuthProtocolVersion::One => 1, + AuthProtocolVersion::Two => 2, + }) + } +} + +// workaround until is merged +// PR: ( Integer/boolean tags for internally/adjacently tagged enums #2056 ) +#[cfg(feature = "serde")] +impl<'de> Deserialize<'de> for AuthProtocolVersion { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + use serde::de; + + match u8::deserialize(deserializer)? { + 1 => Ok(Self::One), + 2 => Ok(Self::Two), + i => Err(de::Error::invalid_value( + de::Unexpected::Unsigned(i.into()), + &"1 or 2", + )), + } + } +} + pub enum Subcommand { GetPinRetries, GetKeyAgreement,