Skip to main content

encrypted_stream

Function encrypted_stream 

Source
pub fn encrypted_stream<R: AsyncRead, W: AsyncWrite, A, S>(
    read: R,
    write: W,
    key: &Array<u8, A::KeySize>,
    nonce: &Array<u8, NonceSize<A, S>>,
) -> EncryptedStream<R, W, A, S>
Expand description

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

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

use async_encrypted_stream::{ReadHalf, WriteHalf, encrypted_stream};

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());