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 example
Encrypt and decrypt message with an in-memory buffer.
// Generate random key and IV for the operations.
let = keygen;
let input = "Hello world!";
// Encryption into a new `Vec<u8>`. (Any implementor of `io::Write` or `&mut io::Write` can be used.)
let mut sink = encrypt.expect;
sink.write_all.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<u8>`. (Any implementor of `std::io::Write` or `&mut std::io::Write` can be used.)
let mut sink = decrypt.expect;
sink.write_all.unwrap;
sink.flush.unwrap;
let output_decrypted = sink.into_inner;
assert_eq!;
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.2AsyncWrite
. The API is the same as for the regularSink
. - explicit_clear - Explicitly clear in-memory buffer after operations.
License
MIT