use thiserror::Error;
use crate::errors::IoError;
#[derive(Clone, Debug, Error)]
#[non_exhaustive]
pub enum AuthError {
#[error("No authentication data provided")]
NoAuthProvided,
#[error("Invalid format for Authorization header")]
InvalidAuthHeader,
#[error("Unknown authentication scheme: {0}")]
UnknownAuthScheme(String),
#[error("Authentication payload decoding error: {0}")]
PayloadDecode(#[from] base64::DecodeError),
#[error("Authentication payload is not printable: {0}")]
NonPrintablePayload(#[from] std::string::FromUtf8Error),
#[error("Invalid authentication payload")]
InvalidAuthPayload,
#[error("Authentication failed")]
UserNotFound,
#[error("Authentication failed")]
AuthFailed,
#[error("User does not have permission: {0}")]
NoPermission(&'static str),
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum AuthSetupError {
#[error("Key loading error (file {0}): {1}")]
KeyIo(String, IoError),
#[cfg(feature = "jwt")]
#[error("Key decoding error: {0}")]
KeyDecode(#[from] jsonwebtoken::errors::Error),
}