use snafu::Snafu;
use crate::BoxedError;
#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
pub enum VerifyError<E: crate::Error> {
#[snafu(display("no matching key"))]
NoMatchingKey,
#[snafu(display("ambiguous key: multiple keys match but token has no kid"))]
AmbiguousKeyMatch,
#[snafu(display("signature mismatch"))]
SignatureMismatch,
#[snafu(transparent)]
Other {
source: E,
},
}
impl<E: crate::Error> crate::Error for VerifyError<E> {
fn is_retryable(&self) -> bool {
match self {
VerifyError::NoMatchingKey
| VerifyError::AmbiguousKeyMatch
| VerifyError::SignatureMismatch => false,
VerifyError::Other { source } => source.is_retryable(),
}
}
}
#[derive(Debug, Snafu)]
pub enum CreateVerifierError {
#[snafu(display("Unsupported key"))]
UnsupportedKey,
#[snafu(display("A JWKS URI is required to build a JWS verifier"))]
MissingJwksUri,
#[snafu(transparent)]
Other {
source: BoxedError,
},
}
impl crate::Error for CreateVerifierError {
fn is_retryable(&self) -> bool {
match self {
CreateVerifierError::UnsupportedKey | CreateVerifierError::MissingJwksUri => false,
CreateVerifierError::Other { source } => source.is_retryable(),
}
}
}