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
//! A drop-in replacement for the Rust standard library TCP listener with TLSv1.2 enabled.
//!
//! _Note: This library hasn't been tested._
//!
//! ## Introduction
//!
//! This library abstracts over a regular TCP listener from the Rust standard library,
//! and provides a drop-in* interface replacement that layers TLSv1.2 with a set of
//! strong cipher suites on top of the connection.
//!
//! It uses the [OpenSSL library Rust bindings](https://github.com/sfackler/rust-openssl)
//! by Steven Fackler for the underlying TLS functionality. If you don't trust OpenSSL (I don't),
//! you can compile this crate against LibreSSL (instructions provided below).
//!
//! _* It's only necessary to prepend `Tls` to the regular types (e.g. `TlsTcpListener`),
//! and write error handling code for the new error types._
//!
//! ## Usage
//!
//! Caesar provides a `CaesarError` enum type, with a variant for I/O errors and another one
//! for SSL errors.
//!
//! ```rust
//! extern crate caesar;
//!
//! use caesar::{TlsTcpListener, TlsTcpStream};
//! use std::thread;
//!
//! let key_path = "path_to_certs/key.pem";
//! let cert_path = "path_to_certs/cert.pem";
//!
//! let listener = TlsTcpListener::bind("127.0.0.1:8080", key_path, cert_path).unwrap()
//!
//! fn handle_client(stream: TlsTcpStream) {
//!     // ...
//! }
//!
//! // accept connections and process them, spawning a new thread for each one
//! for stream in listener.incoming() {
//!     match stream {
//!         Ok(stream) => {
//!             thread::spawn(move || {
//!                 // connection succeeded
//!                 handle_client(stream)
//!             });
//!         }
//!         Err(e) => { /* connection failed */ }
//!     }
//! }
//!
//! close the socket server
//! drop(listener);
//! ```

extern crate openssl;

mod types;
mod tcp;

pub use types::{Result, CaesarError};
pub use tcp::*;