7 releases (4 breaking)

Uses new Rust 2024

0.5.1 Sep 20, 2025
0.5.0 Sep 12, 2025
0.4.0 Jun 28, 2025
0.3.0 Dec 2, 2024
0.1.1 Jun 7, 2024

#1382 in Cryptography

Download history 131/week @ 2025-06-25 11/week @ 2025-07-02 7/week @ 2025-07-09 1/week @ 2025-08-20 141/week @ 2025-09-10 135/week @ 2025-09-17 24/week @ 2025-09-24 30/week @ 2025-10-01 4/week @ 2025-10-08

199 downloads per month
Used in 2 crates

MIT license

23KB
359 lines

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 pre-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??;

gday_encryption

Crates.io Version docs.rs

Simple encrypted ChaCha20Poly1305 wrapper around an async IO stream. Uses a streaming chacha20poly1305 cipher.

See the documentation.

Used by

  • gday - Command line tool for sending files.
  • gday_gui - GUI app for sending files.

Dependencies

~4–14MB
~134K SLoC