1use std::string::FromUtf8Error;
4
5use http::header::InvalidHeaderValue;
6use thiserror::Error;
7
8#[derive(Debug, Error)]
10pub enum CredentialsDecodeError {
11 #[error(transparent)]
13 Base64DecodeError(#[from] base64::DecodeError),
14 #[error(transparent)]
16 UnicodeDecodeError(#[from] FromUtf8Error),
17 #[error("Delimiter missing, credentials must be in a user:pass format")]
19 DelimiterNotFound,
20}
21
22#[derive(Debug, Error)]
23pub enum ParseError {
25 #[error("Authorization header is missing from the header map")]
27 AuthHeaderMissing,
28 #[error("Authorization header contains invalid characters")]
30 InvalidCharacters,
31 #[error("Bad authorization header format")]
33 BadFormat,
34 #[error("The authentication type {0} is unsupported")]
36 UnknownAuthenticationType(String),
37 #[error("User credentials format is invalid")]
39 InvalidUserCredentialsFormat,
40 #[error(transparent)]
42 CredentialsDecodeError(#[from] CredentialsDecodeError),
43 #[error(transparent)]
45 InvalidHeaderValue(#[from] InvalidHeaderValue),
46}
47
48impl ParseError {
49 pub fn unknown_authentication_type<S: Into<String>>(auth_type: S) -> Self {
51 Self::UnknownAuthenticationType(auth_type.into())
52 }
53}