Crate gday_encryption

Source
Expand description

Simple encrypted ChaCha20Poly1305 wrapper around an async IO stream.

This library is used by gday_file_transfer, which is used by gday.

In general, I recommend using the well-established rustls for encryption. gday_file_transfer chose this library because rustls didn’t support peer-to-peer connections with a shared key.

§Example

// Example pipe (like a TCP connection).
let (mut sender, mut receiver) = tokio::io::duplex(64);

// Both peers must have the same key
let key: [u8; 32] = [123; 32];

let handle = tokio::spawn(async move {
    // Peer 1 sends "Hello!"
    let mut stream = EncryptedStream::encrypt_connection(
        &mut sender,
        &key,
    ).await?;
    stream.write_all(b"Hello!").await?;
    stream.flush().await?;

    Ok::<(), std::io::Error>(())
});

// Peer 2 receives the "Hello!".
let mut stream = EncryptedStream::encrypt_connection(
    &mut receiver,
    &key,
).await?;
let mut received = [0u8; 6];
stream.read_exact(&mut received).await?;

assert_eq!(b"Hello!", &received);

handle.await??;

Structs§

EncryptedStream
A simple encrypted wrapper around an IO stream. Uses chacha20poly1305 with the chacha20poly1305::aead::stream.