use thiserror::Error;
pub(super) type VerificationResult<T> =
std::result::Result<T, VerificationError>;
#[derive(Debug, Error)]
pub enum VerificationError {
#[error("Invalid signature")]
InvalidSignature,
#[error("Invalid key algorithm")]
InvalidKeyAlgorithm,
#[error("Invalid token")]
InvalidToken,
#[error("Missing 'kid' header in token")]
NoKidHeader,
#[error("No matching public key found for 'kid'")]
NoMatchingKid,
#[error("Could not decode public keys")]
CannotDecodePublicKeys,
#[error("Could not decode public keys")]
CannotDecodeJwt(#[from] base64::DecodeError),
}
#[derive(Debug, thiserror::Error)]
pub enum PublicKeysError {
#[error("failed to fetch public keys from the identity provider: {0}")]
FetchPublicKeys(reqwest::Error),
#[error("missing 'Cache-Control' header in the response")]
MissingCacheControlHeader,
#[error("the 'max-age' directive is present but empty")]
EmptyMaxAgeDirective,
#[error("the 'max-age' directive is not a valid number")]
InvalidMaxAgeValue,
#[error("no 'max-age' directive found in 'Cache-Control' header")]
MissingMaxAgeDirective,
#[error("failed to parse one or more public keys: {0}")]
PublicKeyParseError(reqwest::Error),
}