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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Signed, encrypted session cookies for Iron.
//!
//! A more complete reference implementation can be found on
//! [github](https://github.com/heartsucker/iron-reference).
//!
//! # Hello, Secure Session!
//!
//! ```
//! extern crate iron;
//! extern crate secure_session;
//! extern crate typemap;
//!
//! use serde::{Deserialize, Serialize};
//! use iron::AroundMiddleware;
//! use iron::prelude::*;
//! use iron::status;
//!
//! use secure_session::middleware::{SessionMiddleware, SessionConfig};
//! use secure_session::session::ChaCha20Poly1305SessionManager;
//!
//! fn main() {
//!     let key = *b"01234567012345670123456701234567";
//!     let manager = ChaCha20Poly1305SessionManager::<Session>::from_key(key);
//!     let config = SessionConfig::default();
//!     let middleware =
//!         SessionMiddleware::<Session, SessionKey, ChaCha20Poly1305SessionManager<Session>>::new(
//!             manager, config);
//!
//!     let handler = middleware.around(Box::new(index));
//!
//!     Iron::new(handler); //.http("localhost:8080").unwrap();
//! }
//!
//! fn index(request: &mut Request) -> IronResult<Response> {
//!     let message = request.extensions.get::<SessionKey>()
//!         .map(|s| s.message.clone())
//!         .unwrap_or("secure session".to_string());
//!     Ok(Response::with((status::Ok, format!("Hello, {}!", message))))
//! }
//!
//! #[derive(Serialize, Deserialize)]
//! struct Session {
//!     message: String,
//! }
//!
//! struct SessionKey {}
//!
//! impl typemap::Key for SessionKey {
//!     type Value = Session;
//! }
//! ```

#![deny(missing_docs)]

#[macro_use]
extern crate log;

/// The name of the cookie that stores the session.
pub const SESSION_COOKIE_NAME: &'static str = "ss";

pub mod error;
pub mod middleware;
pub mod session;