1use std::{error, fmt};
2
3#[derive(Debug, PartialEq)]
5pub enum Error {
6 Protocol(Kind),
10 UnsupportedExtension,
12 InvalidServer,
15 Authentication(String),
17 InvalidUser(String),
19}
20
21#[derive(Debug, PartialEq)]
23pub enum Kind {
24 InvalidNonce,
26 InvalidField(Field),
28 ExpectedField(Field),
30}
31
32#[derive(Debug, PartialEq)]
34pub enum Field {
35 Nonce,
37 Salt,
39 Iterations,
41 VerifyOrError,
43 ChannelBinding,
45 Authzid,
47 Authcid,
49 GS2Header,
51 Proof,
53}
54
55impl fmt::Display for Error {
56 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
57 use self::Error::*;
58 use self::Kind::*;
59 match *self {
60 Protocol(InvalidNonce) => write!(fmt, "Invalid nonce"),
61 Protocol(InvalidField(ref field)) => write!(fmt, "Invalid field {:?}", field),
62 Protocol(ExpectedField(ref field)) => write!(fmt, "Expected field {:?}", field),
63 UnsupportedExtension => write!(fmt, "Unsupported extension"),
64 InvalidServer => write!(fmt, "Server failed validation"),
65 InvalidUser(ref username) => write!(fmt, "Invalid user: '{}'", username),
66 Authentication(ref msg) => write!(fmt, "authentication error {}", msg),
67 }
68 }
69}
70
71impl error::Error for Error {
72 fn description(&self) -> &str {
73 use self::Error::*;
74 use self::Kind::*;
75 match *self {
76 Protocol(InvalidNonce) => "Invalid nonce",
77 Protocol(InvalidField(_)) => "Invalid field",
78 Protocol(ExpectedField(_)) => "Expected field",
79 UnsupportedExtension => "Unsupported extension",
80 InvalidServer => "Server failed validation",
81 InvalidUser(_) => "Invalid user",
82 Authentication(_) => "Unspecified error",
83 }
84 }
85}