tokio_noise/
lib.rs

1//! # tokio-noise
2//!
3//! An authenticated encryption layer on top of [tokio](https://tokio.rs) streams,
4//! driven by the [Noise Protocol Framework](https://noiseprotocol.org/).
5//!
6//! This library is [sponsored by DLC.Link](https://www.dlc.link/).
7//!
8//! ```no_run
9//! use tokio::net::{TcpListener, TcpStream};
10//! use tokio_noise::{NoiseError, NoiseTcpStream};
11//!
12//! const PSK: [u8; 32] = [0xFF; 32];
13//!
14//! async fn run_noise_server(tcp_stream: TcpStream) -> Result<(), NoiseError> {
15//!     let mut noise_stream = NoiseTcpStream::handshake_responder_psk0(tcp_stream, &PSK).await?;
16//!     let mut buf = [0u8; 1024];
17//!     let n = noise_stream.recv(&mut buf).await?;
18//!     assert_eq!(&buf[..n], b"hello world");
19//!     Ok(())
20//! }
21//!
22//! #[tokio::main]
23//! async fn main() -> Result<(), NoiseError> {
24//!     let listener = TcpListener::bind("127.0.0.1:0").await?;
25//!     let addr = listener.local_addr()?;
26//!
27//!     let srv = tokio::task::spawn(async move {
28//!         let (tcp_stream, _) = listener.accept().await?;
29//!         run_noise_server(tcp_stream).await
30//!     });
31//!
32//!     // Client
33//!     let tcp_stream = TcpStream::connect(&addr).await?;
34//!     let mut noise_stream = NoiseTcpStream::handshake_initiator_psk0(tcp_stream, &PSK).await?;
35//!     noise_stream.send(b"hello world").await?;
36//!
37//!     // Wait for server to finish
38//!     srv.await.unwrap()?;
39//!
40//!     Ok(())
41//! }
42//! ```
43
44#![warn(missing_docs)]
45
46mod errors;
47pub mod handshakes;
48mod tcp;
49
50pub use errors::*;
51pub use tcp::*;
52
53pub use snow;