digest_auth/
error.rs

1use std::fmt::{self, Display, Formatter};
2use std::result;
3
4#[derive(Debug, PartialEq)]
5pub enum Error {
6    BadCharset(String),
7    UnknownAlgorithm(String),
8    BadQop(String),
9    MissingRequired(&'static str, String),
10    InvalidHeaderSyntax(String),
11    BadQopOptions(String),
12    NumParseError,
13}
14
15pub type Result<T> = result::Result<T, Error>;
16
17use Error::*;
18
19impl Display for Error {
20    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
21        match self {
22            BadCharset(ctx) => write!(f, "Bad charset: {}", ctx),
23            UnknownAlgorithm(ctx) => write!(f, "Unknown algorithm: {}", ctx),
24            BadQop(ctx) => write!(f, "Bad Qop option: {}", ctx),
25            MissingRequired(what, ctx) => write!(f, "Missing \"{}\" in header: {}", what, ctx),
26            InvalidHeaderSyntax(ctx) => write!(f, "Invalid header syntax: {}", ctx),
27            BadQopOptions(ctx) => write!(f, "Illegal Qop in prompt: {}", ctx),
28            NumParseError => write!(f, "Error parsing a number."),
29        }
30    }
31}
32
33impl From<std::num::ParseIntError> for Error {
34    fn from(_: std::num::ParseIntError) -> Self {
35        NumParseError
36    }
37}
38
39impl std::error::Error for Error {}