#[cfg(not(any(feature = "auth-basic", feature = "auth-bearer")))]
compile_error!(r#"At least one feature must be enabled!"#);
#[cfg(feature = "auth-basic")]
mod auth_basic;
#[cfg(feature = "auth-bearer")]
mod auth_bearer;
#[cfg(feature = "auth-basic")]
pub use auth_basic::{AuthBasic,AuthBasicCustom};
#[cfg(feature = "auth-bearer")]
pub use auth_bearer::{AuthBearer,AuthBearerCustom};
use http::{header::AUTHORIZATION, request::Parts, StatusCode};
pub type Rejection = (StatusCode, &'static str);
pub(crate) const ERR_DEFAULT: StatusCode = StatusCode::BAD_REQUEST;
pub(crate) const ERR_MISSING: &str = "`Authorization` header is missing";
pub(crate) const ERR_CHARS: &str = "`Authorization` header contains invalid characters";
pub(crate) const ERR_DECODE: &str = "`Authorization` header could not be decoded";
pub(crate) const ERR_WRONG_BASIC: &str = "`Authorization` header must be for basic authentication";
pub(crate) const ERR_WRONG_BEARER: &str = "`Authorization` header must be a bearer token";
pub(crate) trait DecodeRequestParts: Sized {
fn decode_request_parts(req: &mut Parts, err_code: StatusCode) -> Result<Self, Rejection>;
}
pub(crate) fn get_header(parts: &mut Parts, err_code: StatusCode) -> Result<&str, Rejection> {
parts
.headers
.get(AUTHORIZATION)
.ok_or((err_code, ERR_MISSING))?
.to_str()
.map_err(|_| (err_code, ERR_CHARS))
}