passkey_types/ctap2/extensions/
prf.rs

1//! While this is not an official CTAP extension,
2//! it is used on Windows directly and it allows an in-memory authenticator
3//! to handle the prf extension in a more efficient manor.
4
5use std::collections::HashMap;
6
7use serde::{Deserialize, Serialize};
8
9use crate::{webauthn, Bytes};
10
11#[cfg(doc)]
12use crate::ctap2::{get_assertion, make_credential};
13
14/// This struct is a more opiniated mirror of [`webauthn::AuthenticationExtensionsPrfInputs`].
15#[derive(Debug, Serialize, Deserialize, Clone)]
16pub struct AuthenticatorPrfInputs {
17    /// See  [`webauthn::AuthenticationExtensionsPrfInputs::eval`].
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    pub eval: Option<AuthenticatorPrfValues>,
20
21    /// See  [`webauthn::AuthenticationExtensionsPrfInputs::eval_by_credential`].
22    #[serde(default, skip_serializing_if = "Option::is_none")]
23    pub eval_by_credential: Option<HashMap<Bytes, AuthenticatorPrfValues>>,
24}
25
26/// This struct is a more opiniated mirror of [`webauthn::AuthenticationExtensionsPrfValues`].
27#[derive(Debug, Serialize, Deserialize, Clone)]
28pub struct AuthenticatorPrfValues {
29    /// This is the already hashed values of [`webauthn::AuthenticationExtensionsPrfValues::first`].
30    pub first: [u8; 32],
31
32    /// This is the already hashed values of [`webauthn::AuthenticationExtensionsPrfValues::second`].
33    #[serde(default, skip_serializing_if = "Option::is_none")]
34    pub second: Option<[u8; 32]>,
35}
36
37impl From<AuthenticatorPrfValues> for webauthn::AuthenticationExtensionsPrfValues {
38    fn from(value: AuthenticatorPrfValues) -> Self {
39        Self {
40            first: value.first.to_vec().into(),
41            second: value.second.map(|b| b.to_vec().into()),
42        }
43    }
44}
45
46/// This struct is a more opiniated mirror of [`webauthn::AuthenticationExtensionsPrfOutputs`]
47/// specifically for [`make_credential`].
48#[derive(Debug, Serialize, Deserialize, Clone)]
49pub struct AuthenticatorPrfMakeOutputs {
50    /// See [`webauthn::AuthenticationExtensionsPrfOutputs::enabled`].
51    pub enabled: bool,
52
53    /// See [`webauthn::AuthenticationExtensionsPrfOutputs::results`].
54    #[serde(default, skip_serializing_if = "Option::is_none")]
55    pub results: Option<AuthenticatorPrfValues>,
56}
57
58impl From<AuthenticatorPrfMakeOutputs> for webauthn::AuthenticationExtensionsPrfOutputs {
59    fn from(value: AuthenticatorPrfMakeOutputs) -> Self {
60        Self {
61            enabled: Some(value.enabled),
62            results: value.results.map(Into::into),
63        }
64    }
65}
66
67/// This struct is a more opiniated mirror of [`webauthn::AuthenticationExtensionsPrfOutputs`]
68/// specifically for [`get_assertion`].
69#[derive(Debug, Serialize, Deserialize, Clone)]
70pub struct AuthenticatorPrfGetOutputs {
71    /// See [`webauthn::AuthenticationExtensionsPrfOutputs::results`].
72    pub results: AuthenticatorPrfValues,
73}
74
75impl From<AuthenticatorPrfGetOutputs> for webauthn::AuthenticationExtensionsPrfOutputs {
76    fn from(value: AuthenticatorPrfGetOutputs) -> Self {
77        Self {
78            enabled: None,
79            results: Some(value.results.into()),
80        }
81    }
82}