From 09f361f8a0a9ab0dbba2a3954f978225791d7025 Mon Sep 17 00:00:00 2001 From: Avril Date: Thu, 8 Apr 2021 20:02:43 +0100 Subject: [PATCH] stable release 1.0 --- Cargo.toml | 6 +++++- README.md | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/Cargo.toml b/Cargo.toml index 7355dba..5997058 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,10 @@ [package] name = "chacha20stream" -version = "0.1.0" +version = "1.0.0" +keywords = ["chacha20_poly1305", "stream", "wrapper", "encryption", "decryption"] +description = "A writable wrapper stream for encryption and decryption with the stream cipher chacha20_poly1305" +homepage = "https://git.flanchan.moe/flanchan/chacha20stream" +repository = "https://github.com/notflan/chacha20stream" authors = ["Avril "] edition = "2018" license = "MIT" diff --git a/README.md b/README.md new file mode 100644 index 0000000..36db305 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# chacha20_poly1305 stream wrapper +Contains a writable stream that wraps another, applying the chacha20_poly1305 cipher to the input before writing for either encryption or decryption. + +## Usage +Encrypt and decrypt message with an in-memory buffer. +```rust +// Generate random key and IV for the operations. +let (key, iv) = chacha20stream::keygen(); + +let input = "Hello world!"; + +// Encryption into a new `Vec`. +let mut sink = Sink::encrypt(Vec::new(), key, iv).expect("Failed to create encryptor"); +sink.write_all(input.as_bytes()).unwrap(); +sink.flush().unwrap(); // `flush` also clears the in-memory buffer if there is left over data in it. + +let output_encrypted = sink.into_inner(); + +// Decryption into a new `Vec` +let mut sink = Sink::decrypt(Vec::new(), key, iv).expect("Failed to create decryptor"); +sink.write_all(&output_encrypted[..]).unwrap(); +sink.flush().unwrap(); + +let output_decrypted = sink.into_inner(); + +assert_eq!(&output_decrypted[..], input.as_bytes()); +``` + +# Features +* **smallvec** - Use `smallvec` crate to store the in-memory buffer on the stack if it's smalle enough (*default*) +* **async** - Enable `AsyncSink` with Tokio *0.2* `AsyncWrite`. The API is the same as for the regular `Sink`. +* **explicit_clear** - Explicitly clear in-memory buffer after operations. + +# License +MIT