1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! Module containing the CSRF error types.
//!

use std::error::Error;
use std::fmt;

use iron::prelude::*;
use iron::status;

/// An `enum` of all CSRF related errors.
#[derive(Debug)]
pub enum CsrfError {
    InternalError,
    ValidationFailure,
}

impl Error for CsrfError {
    fn description(&self) -> &str {
        match *self {
            CsrfError::InternalError => "Internal Server Error (CSRF)",
            CsrfError::ValidationFailure => "Forbidden: CSRF Validation Failed",
        }
    }
}

impl fmt::Display for CsrfError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self)
    }
}

impl From<CsrfError> for IronError {
    fn from(err: CsrfError) -> IronError {
        IronError {
            response: Response::with((status::Forbidden, format!("{}", err))),
            error: Box::new(err),
        }
    }
}

pub enum CsrfConfigError {
    // TODO add more of these
    InvalidTtl,
    NoProtectedMethods,
    Unspecified,
}