use serde::{Deserialize, Serialize};
use std::error::Error as StdError;
use std::fmt;
#[derive(Debug)]
pub struct PasskiError(pub String);
impl PasskiError {
pub(crate) fn new(msg: impl Into<String>) -> Self {
Self(msg.into())
}
}
impl fmt::Display for PasskiError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl StdError for PasskiError {}
pub type Result<T> = std::result::Result<T, Box<dyn StdError>>;
#[derive(Serialize, Debug)]
#[serde(rename_all = "lowercase")]
pub enum AttestationConveyancePreference {
None,
Indirect,
Direct,
Enterprise,
}
#[derive(Serialize, Debug)]
#[serde(rename_all = "lowercase")]
pub enum ResidentKeyRequirement {
Discouraged,
Preferred,
Required,
}
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug)]
#[serde(rename_all = "lowercase")]
pub enum UserVerificationRequirement {
Required,
Preferred,
Discouraged,
}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct StoredPasskey {
pub credential_id: Vec<u8>,
pub public_key: Vec<u8>,
pub counter: u32,
pub algorithm: i32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub rk: Option<bool>,
}
#[derive(Serialize, Debug)]
pub struct RelyingParty {
pub name: String,
pub id: String,
}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct UserInfo {
pub id: String,
pub name: String,
#[serde(rename = "displayName")]
pub display_name: String,
}
#[derive(Serialize, Debug)]
pub struct PubKeyCredParam {
pub alg: i32,
#[serde(rename = "type")]
pub type_: String,
}
#[derive(Serialize, Debug)]
pub struct AuthenticatorSelection {
#[serde(rename = "residentKey")]
pub resident_key: ResidentKeyRequirement,
#[serde(rename = "userVerification")]
pub user_verification: UserVerificationRequirement,
}
#[derive(Serialize, Debug)]
pub struct ExcludeCredential {
pub id: String,
#[serde(rename = "type")]
pub type_: String,
}
#[derive(Serialize)]
pub struct AllowCredential {
pub id: String,
#[serde(rename = "type")]
pub type_: String,
}
#[derive(Serialize, Debug, Default)]
pub struct RegistrationExtensions {
#[serde(rename = "credProps", skip_serializing_if = "Option::is_none")]
pub cred_props: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prf: Option<PrfInput>,
}
#[derive(Serialize, Debug)]
pub struct AuthenticationExtensions {
pub prf: PrfInput,
}
#[derive(Serialize, Debug, Default)]
pub struct PrfInput {
#[serde(skip_serializing_if = "Option::is_none")]
pub eval: Option<PrfEval>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PrfEval {
pub first: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub second: Option<String>,
}
#[derive(Deserialize, Debug, Default)]
pub struct ClientExtensionResults {
#[serde(default, rename = "credProps")]
pub cred_props: Option<CredPropsResult>,
#[serde(default)]
pub prf: Option<PrfExtensionResult>,
}
#[derive(Deserialize, Debug)]
pub struct CredPropsResult {
pub rk: Option<bool>,
}
#[derive(Deserialize, Debug)]
pub struct PrfExtensionResult {
pub enabled: Option<bool>,
pub results: Option<PrfResults>,
}
#[derive(Deserialize, Debug)]
pub struct PrfResults {
pub first: Option<String>,
pub second: Option<String>,
}