From 9fb9fa95047e914a59a07fcd2819790e6754b761 Mon Sep 17 00:00:00 2001 From: "John M. Schanck" Date: Thu, 7 Sep 2023 14:53:26 -0700 Subject: [PATCH] Derive Serialize for GetAssertionExtensions --- src/ctap2/commands/get_assertion.rs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/ctap2/commands/get_assertion.rs b/src/ctap2/commands/get_assertion.rs index 3dfeeed..1260645 100644 --- a/src/ctap2/commands/get_assertion.rs +++ b/src/ctap2/commands/get_assertion.rs @@ -133,9 +133,11 @@ impl Serialize for HmacSecretExtension { } } -#[derive(Debug, Clone, Default)] +#[derive(Debug, Default, Clone, Serialize)] pub struct GetAssertionExtensions { + #[serde(skip_serializing)] pub app_id: Option, + #[serde(rename = "hmac-secret", skip_serializing_if = "Option::is_none")] pub hmac_secret: Option, } @@ -148,19 +150,8 @@ impl From for GetAssertionExtensions { } } -impl Serialize for GetAssertionExtensions { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let mut map = serializer.serialize_map(Some(1))?; - map.serialize_entry(&"hmac-secret", &self.hmac_secret)?; - map.end() - } -} - impl GetAssertionExtensions { - fn has_extensions(&self) -> bool { + fn has_content(&self) -> bool { self.hmac_secret.is_some() } } @@ -275,7 +266,7 @@ impl Serialize for GetAssertion { if !self.allow_list.is_empty() { map_len += 1; } - if self.extensions.has_extensions() { + if self.extensions.has_content() { map_len += 1; } if self.options.has_some() { @@ -301,7 +292,7 @@ impl Serialize for GetAssertion { if !self.allow_list.is_empty() { map.serialize_entry(&3, &self.allow_list)?; } - if self.extensions.has_extensions() { + if self.extensions.has_content() { map.serialize_entry(&4, &self.extensions)?; } if self.options.has_some() {