secure_session/lib.rs
1//! Signed, encrypted session cookies for Iron.
2//!
3//! A more complete reference implementation can be found on
4//! [github](https://github.com/heartsucker/iron-reference).
5//!
6//! # Hello, Secure Session!
7//!
8//! ```
9//! extern crate iron;
10//! extern crate secure_session;
11//! extern crate typemap;
12//!
13//! use serde::{Deserialize, Serialize};
14//! use iron::AroundMiddleware;
15//! use iron::prelude::*;
16//! use iron::status;
17//!
18//! use secure_session::middleware::{SessionMiddleware, SessionConfig};
19//! use secure_session::session::ChaCha20Poly1305SessionManager;
20//!
21//! fn main() {
22//! let key = *b"01234567012345670123456701234567";
23//! let manager = ChaCha20Poly1305SessionManager::<Session>::from_key(key);
24//! let config = SessionConfig::default();
25//! let middleware =
26//! SessionMiddleware::<Session, SessionKey, ChaCha20Poly1305SessionManager<Session>>::new(
27//! manager, config);
28//!
29//! let handler = middleware.around(Box::new(index));
30//!
31//! Iron::new(handler); //.http("localhost:8080").unwrap();
32//! }
33//!
34//! fn index(request: &mut Request) -> IronResult<Response> {
35//! let message = request.extensions.get::<SessionKey>()
36//! .map(|s| s.message.clone())
37//! .unwrap_or("secure session".to_string());
38//! Ok(Response::with((status::Ok, format!("Hello, {}!", message))))
39//! }
40//!
41//! #[derive(Serialize, Deserialize)]
42//! struct Session {
43//! message: String,
44//! }
45//!
46//! struct SessionKey {}
47//!
48//! impl typemap::Key for SessionKey {
49//! type Value = Session;
50//! }
51//! ```
52
53#![deny(missing_docs)]
54
55#[macro_use]
56extern crate log;
57
58/// The name of the cookie that stores the session.
59pub const SESSION_COOKIE_NAME: &'static str = "ss";
60
61pub mod error;
62pub mod middleware;
63pub mod session;