fido-common: Implement serde for credential::public_key::Descriptor

Adds serde_with as a dependency in order to serialize Descriptor::id as
bytes instead of as a sequence.

Enables cfg_eval feature to enable conditional usage of serde_with
behind the "serde" feature flag for the fido-common crate.
main
Nick Zana 2 years ago
parent 576addac1f
commit 42044f2a46

@ -9,7 +9,8 @@ edition = "2021"
ciborium = { version = "0.2.1", default-features = false, optional = true }
coset = { version = "0.3.4", default-features = false }
serde = { version = "1", features = ["derive"], optional = true }
serde_with = { path = "../../../serde_with/serde_with", optional = true }
bitflags = { version = "2.2.1", default-features = false, optional = true }
[features]
serde = ["dep:serde", "dep:bitflags", "dep:ciborium"]
serde = ["dep:serde", "dep:serde_with", "dep:bitflags", "dep:ciborium"]

@ -3,6 +3,8 @@ use std::collections::BTreeSet;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "serde")]
use serde_with::{serde_as, skip_serializing_none, Bytes};
#[cfg(feature = "serde")]
pub(crate) mod algorithm {
@ -48,8 +50,14 @@ pub struct Parameters {
}
/// > This dictionary identifies a specific public key credential.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug)]
#[cfg_eval]
#[derive(Debug, Clone)]
#[cfg_attr(
feature = "serde",
serde_as,
skip_serializing_none,
derive(Serialize, Deserialize)
)]
pub struct Descriptor {
/// > This member contains the type of the public key credential
/// > the caller is referring to.
@ -58,6 +66,8 @@ pub struct Descriptor {
/// > A probabilistically-unique byte sequence identifying a
/// > public key credential source and its authentication
/// > assertions.
// Bounds: [16, 1023] bytes
#[cfg_attr(feature = "serde", serde_as(as = "Bytes"))]
pub id: Vec<u8>,
/// > This... member contains a hint as to how the client might
/// > communicate with the managing authenticator of the public

@ -1,4 +1,4 @@
#![feature(split_array, slice_take)]
#![feature(cfg_eval, split_array, slice_take)]
pub mod attestation;
pub mod authenticator;

Loading…
Cancel
Save