From 7f8f97b0c311b446aec41184ca29923e7fe74f09 Mon Sep 17 00:00:00 2001 From: Nick Zana Date: Wed, 17 May 2023 23:19:29 -0400 Subject: [PATCH] ctap2-proto: Derive builder trait for authenticator::credential::make::Request Adds typed-builder dependency to derive Builder struct. --- crates/ctap2-proto/Cargo.toml | 1 + crates/ctap2-proto/src/authenticator/credential/make.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/crates/ctap2-proto/Cargo.toml b/crates/ctap2-proto/Cargo.toml index c766155..d4a9976 100644 --- a/crates/ctap2-proto/Cargo.toml +++ b/crates/ctap2-proto/Cargo.toml @@ -10,6 +10,7 @@ fido-common = { path = "../fido-common" } bounded-integer = { version = "0.5.3", features = ["types", "std"] } coset = "0.3.3" serde = { version = "=1.0.136", features = ["derive"], optional = true } +typed-builder = { version = "0.14.0", default-features = false } # Version <= to support older serde serde_with = { version = "<=2.2.0", optional = true } diff --git a/crates/ctap2-proto/src/authenticator/credential/make.rs b/crates/ctap2-proto/src/authenticator/credential/make.rs index 8bf57a3..9d147ff 100644 --- a/crates/ctap2-proto/src/authenticator/credential/make.rs +++ b/crates/ctap2-proto/src/authenticator/credential/make.rs @@ -4,6 +4,7 @@ use crate::{ }; use fido_common::{attestation, credential::public_key}; use std::collections::BTreeMap; +use typed_builder::TypedBuilder; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -52,6 +53,7 @@ pub enum OptionKey { #[cfg_eval] /// Input parameters for [`Ctap2Device::make_credential`] operation. #[cfg_attr(feature = "serde", serde_as, skip_serializing_none, derive(Serialize))] +#[derive(Debug, Clone, Copy, TypedBuilder)] pub struct Request<'a> { /// > Hash of the ClientData contextual binding specified by host. #[cfg_attr(feature = "serde", serde(rename = 0x01), serde_as(as = "Bytes"))] @@ -76,14 +78,18 @@ pub struct Request<'a> { /// > authenticator already contains one of the credentials enumerated /// > in this array. This allows RPs to limit the creation of multiple /// > credentials for the same account on a single authenticator. + #[builder(default, setter(strip_option))] #[cfg_attr(feature = "serde", serde(rename = 0x05))] pub exclude_list: Option<&'a [&'a public_key::Descriptor]>, /// > Parameters to influence authenticator operation, as specified in /// > [WebAuthn]. These parameters might be authenticator specific. + #[builder(default, setter(strip_option))] #[cfg_attr(feature = "serde", serde(rename = 0x06))] pub extensions: Option<&'a BTreeMap>>, + #[builder(default, setter(strip_option))] #[cfg_attr(feature = "serde", serde(rename = 0x07))] pub options: Option<&'a BTreeMap>, + #[builder(default, setter(strip_option))] #[cfg_attr( feature = "serde", serde(rename = 0x08), @@ -91,6 +97,7 @@ pub struct Request<'a> { )] pub pin_uv_auth_param: Option<&'a [u8]>, /// > PIN/UV protocol version selected by platform. + #[builder(default, setter(strip_option))] #[cfg_attr(feature = "serde", serde(rename = 0x09))] pub pin_uv_auth_protocol_version: Option, /// > An authenticator supporting this enterprise attestation feature is @@ -105,6 +112,7 @@ pub struct Request<'a> { /// > attestation batching may not apply to the results of this operation /// > and the platform is requesting an enterprise attestation that includes /// > uniquely identifying information. + #[builder(default, setter(strip_option))] #[cfg_attr(feature = "serde", serde(rename = 0x0A))] pub enterprise_attestation: Option, }