use std::string::FromUtf8Error;
use http::header::InvalidHeaderValue;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum CredentialsDecodeError {
#[error(transparent)]
Base64DecodeError(#[from] base64::DecodeError),
#[error(transparent)]
UnicodeDecodeError(#[from] FromUtf8Error),
#[error("Delimiter missing, credentials must be in a user:pass format")]
DelimiterNotFound,
}
#[derive(Debug, Error)]
pub enum ParseError {
#[error("Authorization header is missing from the header map")]
AuthHeaderMissing,
#[error("Authorization header contains invalid characters")]
InvalidCharacters,
#[error("Bad authorization header format")]
BadFormat,
#[error("The authentication type {0} is unsupported")]
UnknownAuthenticationType(String),
#[error("User credentials format is invalid")]
InvalidUserCredentialsFormat,
#[error(transparent)]
CredentialsDecodeError(#[from] CredentialsDecodeError),
#[error(transparent)]
InvalidHeaderValue(#[from] InvalidHeaderValue),
}
impl ParseError {
pub fn unknown_authentication_type<S: Into<String>>(auth_type: S) -> Self {
Self::UnknownAuthenticationType(auth_type.into())
}
}