Skip to main content

session_guard/
error.rs

1//! Error types.
2
3/// Error type stores return. Boxed so store implementations can surface their own errors.
4pub type StoreError = Box<dyn std::error::Error + Send + Sync + 'static>;
5
6/// Errors from guard operations. Request-level outcomes (expired, revoked, step-up) are not
7/// errors; see [`Outcome`](crate::Outcome).
8#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum GuardError {
11    /// The session store failed.
12    #[error("session store error: {0}")]
13    Store(#[from] StoreError),
14    /// The operating system RNG was unavailable, so no token could be generated.
15    #[error("operating system random number generator unavailable")]
16    Random,
17    /// The subject could not be serialized.
18    #[error("subject could not be serialized: {0}")]
19    Subject(String),
20}
21
22/// Invalid [`GuardConfig`](crate::GuardConfig) or [`CookieConfig`](crate::CookieConfig).
23#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
24#[non_exhaustive]
25pub enum ConfigError {
26    /// A trusted proxy entry is neither an IP address nor a CIDR range.
27    #[error("invalid trusted proxy {0:?}: expected an IP address or CIDR range")]
28    InvalidProxy(String),
29    /// The cookie settings are inconsistent or rejected by browsers.
30    #[error("invalid cookie configuration: {0}")]
31    InvalidCookie(&'static str),
32    /// A duration is zero or too large.
33    #[error("invalid duration for {0}: must be greater than zero and fit in a timestamp")]
34    InvalidDuration(&'static str),
35    /// Rotation grace must be shorter than the rotation interval.
36    #[error("rotation grace must be shorter than the rotation interval")]
37    GraceTooLong,
38    /// Thresholds must satisfy `0 < step_up <= revoke`.
39    #[error("thresholds must satisfy 0 < step_up <= revoke")]
40    InvalidThresholds,
41    /// A header name is not a valid lowercase HTTP header name.
42    #[error("invalid header name {0:?}")]
43    InvalidHeaderName(String),
44    /// A token prefix must be 1 to 32 characters of `A-Z a-z 0-9 _ -`.
45    #[error("invalid token prefix {0:?}: expected 1 to 32 characters of A-Z a-z 0-9 _ -")]
46    InvalidTokenPrefix(String),
47}