use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::{Bytes, webauthn};
#[cfg(doc)]
use crate::ctap2::{get_assertion, make_credential};
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct AuthenticatorPrfInputs {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub eval: Option<AuthenticatorPrfValues>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub eval_by_credential: Option<HashMap<Bytes, AuthenticatorPrfValues>>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct AuthenticatorPrfValues {
pub first: [u8; 32],
#[serde(default, skip_serializing_if = "Option::is_none")]
pub second: Option<[u8; 32]>,
}
impl From<AuthenticatorPrfValues> for webauthn::AuthenticationExtensionsPrfValues {
fn from(value: AuthenticatorPrfValues) -> Self {
Self {
first: value.first.to_vec().into(),
second: value.second.map(|b| b.to_vec().into()),
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AuthenticatorPrfMakeOutputs {
pub enabled: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub results: Option<AuthenticatorPrfValues>,
}
impl From<AuthenticatorPrfMakeOutputs> for webauthn::AuthenticationExtensionsPrfOutputs {
fn from(value: AuthenticatorPrfMakeOutputs) -> Self {
Self {
enabled: Some(value.enabled),
results: value.results.map(Into::into),
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AuthenticatorPrfGetOutputs {
pub results: AuthenticatorPrfValues,
}
impl From<AuthenticatorPrfGetOutputs> for webauthn::AuthenticationExtensionsPrfOutputs {
fn from(value: AuthenticatorPrfGetOutputs) -> Self {
Self {
enabled: None,
results: Some(value.results.into()),
}
}
}