Skip to main content

Crate async_encrypted_stream

Crate async_encrypted_stream 

Source
Expand description

§Async Encrypted Stream

Rust dependency status

Async Read and Write wrappers around the chacha20 encryption primitives.

This crate exposes a pair of ReadHalf and WriteHalf structs that works with any tokio::io::AsyncRead and tokio::io::AsyncWrite respectively.

To use this crate, it is necessary to add chacha20poly1305 as a dependency as well.

async-encrypted-stream = "0.2"

Once the necessary dependencies are added, creating the stream is fairly trivial

use async_encrypted_stream::aead_stream::{DecryptorLE31, EncryptorLE31};
use async_encrypted_stream::chacha20poly1305::XChaCha20Poly1305;
use async_encrypted_stream::{ReadHalf, WriteHalf, encrypted_stream};

// The key and nonce used must be the same on both ends of the stream
// NOTE: the size of the key and nonce values are defined by the type of Encryption used
let key = [0u8; 32];
let nonce = [0u8; 20];

let (rx, tx) = tokio::io::duplex(4096);
let (mut reader, mut writer): (
    ReadHalf<_, DecryptorLE31<XChaCha20Poly1305>>,
    WriteHalf<_, EncryptorLE31<XChaCha20Poly1305>>,
) = encrypted_stream(rx, tx, (&key).into(), (&nonce).into());

Re-exports§

pub use aead_stream;
pub use chacha20poly1305;

Structs§

ReadHalf
Async Encryption Read Half
WriteHalf
Async Encryption Write Half.

Constants§

DEFAULT_BUFFER_SIZE
DEFAULT_CHUNK_SIZE

Functions§

encrypted_stream
Creates a pair of ReadHalf and WriteHalf with default buffer size of self::DEFAULT_BUFFER_SIZE and chunk size of self::DEFAULT_CHUNK_SIZE
encrypted_stream_with_capacity
Creates a pair of ReadHalf and WriteHalf with default buffer size of buffer_size and chunk size of chunk_size

Type Aliases§

EncryptedStream