use thiserror::Error;
#[derive(Debug, Error)]
pub enum ParseError {
#[error("Invalid token structure")]
InvalidTokenStructure,
#[error("base64 decoding error: {}", _0)]
Base64(#[from] base64::DecodeError),
#[error("Malformed token header: {}", _0)]
MalformedHeader(#[source] serde_json::Error),
#[error("Unsupported content type: {}", _0)]
UnsupportedContentType(String),
}
#[derive(Debug, Error)]
pub enum ValidationError {
#[error("Token algorithm differs from the expected one")]
AlgorithmMismatch,
#[error("Malformed token signature: {}", _0)]
MalformedSignature(#[source] anyhow::Error),
#[error("Signature has failed verification")]
InvalidSignature,
#[error("Cannot deserialize claims: {}", _0)]
MalformedClaims(#[source] serde_json::Error),
#[error("Cannot deserialize claims: {}", _0)]
MalformedCborClaims(#[source] serde_cbor::error::Error),
#[error("Claim requested during validation is not present in the token")]
NoClaim,
#[error("Token has expired")]
Expired,
#[error("Token is not yet ready")]
NotMature,
}
#[derive(Debug, Error)]
pub enum CreationError {
#[error("Cannot serialize header: {}", _0)]
Header(#[source] serde_json::Error),
#[error("Cannot serialize claims: {}", _0)]
Claims(#[source] serde_json::Error),
#[error("Cannot serialize claims into CBOR: {}", _0)]
CborClaims(#[source] serde_cbor::error::Error),
}