use serde::{Deserialize, Serialize};
#[cfg(feature = "typeshare")]
use typeshare::typeshare;
use crate::{
Bytes,
utils::serde::{ignore_unknown, ignore_unknown_opt_vec},
};
#[cfg(doc)]
use crate::webauthn::{
AuthenticatorAttestationResponse, PublicKeyCredential, PublicKeyCredentialCreationOptions,
PublicKeyCredentialRequestOptions,
};
#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "typeshare", typeshare(serialized_as = "String"))]
pub enum PublicKeyCredentialType {
PublicKey,
#[default]
Unknown,
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "typeshare", typeshare)]
pub struct PublicKeyCredentialDescriptor {
#[serde(rename = "type", deserialize_with = "ignore_unknown")]
pub ty: PublicKeyCredentialType,
pub id: Bytes,
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "ignore_unknown_opt_vec"
)]
pub transports: Option<Vec<AuthenticatorTransport>>,
}
impl PublicKeyCredentialDescriptor {
pub fn is_known(&self) -> bool {
match self.ty {
PublicKeyCredentialType::PublicKey => true,
PublicKeyCredentialType::Unknown => false,
}
}
}
#[derive(Debug, Default, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "typeshare", typeshare(serialized_as = "String"))]
pub enum UserVerificationRequirement {
Required,
#[default]
Preferred,
Discouraged,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
#[cfg_attr(feature = "typeshare", typeshare(serialized_as = "String"))]
pub enum AuthenticatorTransport {
Usb,
Nfc,
Ble,
#[serde(alias = "cable")]
Hybrid,
Internal,
}
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "typeshare", typeshare(serialized_as = "String"))]
pub enum AuthenticatorAttachment {
Platform,
CrossPlatform,
}
#[derive(Debug, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
#[cfg_attr(feature = "typeshare", typeshare(serialized_as = "String"))]
#[non_exhaustive]
pub enum PublicKeyCredentialHints {
SecurityKey,
ClientDevice,
Hybrid,
}