4 releases (2 breaking)
new 0.3.0 | Dec 2, 2024 |
---|---|
0.2.1 | Jul 12, 2024 |
0.2.0 | Jul 8, 2024 |
0.1.1 | Jun 7, 2024 |
#998 in Cryptography
145 downloads per month
Used in gday
23KB
359 lines
gday_encryption
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.
lib.rs
:
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??;
Dependencies
~3.5–10MB
~86K SLoC