libwebauthn 0.7.1

FIDO2 (WebAuthn) and FIDO U2F platform library for Linux written in Rust
Documentation
use std::collections::HashMap;

use serde::Deserialize;
use serde_bytes::ByteBuf;

use crate::{
    ops::webauthn::{Base64UrlString, UserVerificationRequirement},
    proto::ctap2::{
        Ctap2PublicKeyCredentialDescriptor, Ctap2PublicKeyCredentialType, Ctap2Transport,
    },
};

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PublicKeyCredentialRequestOptionsJSON {
    pub challenge: Base64UrlString,
    pub timeout: Option<u32>,
    #[serde(rename = "rpId")]
    pub relying_party_id: Option<String>,
    #[serde(default)]
    pub allow_credentials: Vec<PublicKeyCredentialDescriptorJSON>,
    #[serde(rename = "userVerification", default)]
    pub user_verification: UserVerificationRequirement,
    #[serde(default)]
    pub hints: Vec<String>,
    pub extensions: Option<GetAssertionRequestExtensionsJSON>,
}

#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct PublicKeyCredentialDescriptorJSON {
    pub id: Base64UrlString,
    pub r#type: Ctap2PublicKeyCredentialType,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub transports: Option<Vec<Ctap2Transport>>,
}

impl From<PublicKeyCredentialDescriptorJSON> for Ctap2PublicKeyCredentialDescriptor {
    fn from(value: PublicKeyCredentialDescriptorJSON) -> Self {
        Ctap2PublicKeyCredentialDescriptor {
            r#type: value.r#type,
            id: ByteBuf::from(value.id),
            transports: value.transports,
        }
    }
}

#[derive(Debug, Clone, Default, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetAssertionRequestExtensionsJSON {
    #[serde(rename = "getCredBlob")]
    pub cred_blob: Option<bool>,
    pub large_blob: Option<LargeBlobInputJson>,
    pub hmac_get_secret: Option<HmacGetSecretInputJson>,
    pub prf: Option<PrfInputJson>,
    /// FIDO AppID extension (WebAuthn L3 ยง10.1.1). When the relying party has
    /// existing U2F credentials registered under a legacy AppID, this URL is
    /// hashed in place of the rpId to derive the U2F application parameter.
    pub appid: Option<String>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct LargeBlobInputJson {
    pub support: Option<String>,
    pub read: Option<bool>,
    pub write: Option<Base64UrlString>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct PrfInputJson {
    pub eval: Option<PrfValuesJson>,
    pub eval_by_credential: Option<HashMap<String, PrfValuesJson>>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct PrfValuesJson {
    pub first: Base64UrlString,
    pub second: Option<Base64UrlString>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct HmacGetSecretInputJson {
    pub salt1: Base64UrlString,
    pub salt2: Option<Base64UrlString>,
}