use thiserror::Error;
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum VerifyError {
#[error("missing_credential: X-Signature and X-Attestation are both required")]
MissingCredential,
#[error("malformed: {0}")]
Malformed(String),
#[error("bad_alg: {0}")]
BadAlg(String),
#[error("untrusted_issuer: {0}")]
UntrustedIssuer(String),
#[error("unknown_kid: {0}")]
UnknownKid(String),
#[error("bad_attestation: {0}")]
BadAttestation(String),
#[error("attestation_expired")]
AttestationExpired,
#[error("device_not_active")]
DeviceNotActive,
#[error("bad_jwk: {0}")]
BadJwk(String),
#[error("key_not_bound: embedded jwk thumbprint does not match attestation cnf.jkt")]
KeyNotBound,
#[error("bad_signature: {0}")]
BadSignature(String),
#[error("signature_expired")]
SignatureExpired,
#[error("lifetime_too_long")]
LifetimeTooLong,
#[error("method_mismatch")]
MethodMismatch,
#[error("path_mismatch")]
PathMismatch,
#[error("audience_mismatch")]
AudienceMismatch,
#[error("query_mismatch")]
QueryMismatch,
#[error("body_mismatch")]
BodyMismatch,
#[error("replay_detected")]
ReplayDetected,
#[error("body_too_large: request body exceeds the configured maximum of {0} bytes")]
BodyTooLarge(usize),
}
impl VerifyError {
pub fn code(&self) -> &'static str {
match self {
VerifyError::MissingCredential => "missing_credential",
VerifyError::Malformed(_) => "malformed",
VerifyError::BadAlg(_) => "bad_alg",
VerifyError::UntrustedIssuer(_) => "untrusted_issuer",
VerifyError::UnknownKid(_) => "unknown_kid",
VerifyError::BadAttestation(_) => "bad_attestation",
VerifyError::AttestationExpired => "attestation_expired",
VerifyError::DeviceNotActive => "device_not_active",
VerifyError::BadJwk(_) => "bad_jwk",
VerifyError::KeyNotBound => "key_not_bound",
VerifyError::BadSignature(_) => "bad_signature",
VerifyError::SignatureExpired => "signature_expired",
VerifyError::LifetimeTooLong => "lifetime_too_long",
VerifyError::MethodMismatch => "method_mismatch",
VerifyError::PathMismatch => "path_mismatch",
VerifyError::AudienceMismatch => "audience_mismatch",
VerifyError::QueryMismatch => "query_mismatch",
VerifyError::BodyMismatch => "body_mismatch",
VerifyError::ReplayDetected => "replay_detected",
VerifyError::BodyTooLarge(_) => "body_too_large",
}
}
}