Expand description
Provides a wrapper around a Write/Read object and a
StreamPrimitive to provide an easy interface for doing
correct encryption.
let key = b"my very super super secret key!!".into();
let plaintext = b"hello world!";
let mut ciphertext = Vec::default();
{
let mut writer = EncryptBE32BufWriter::<ChaCha20Poly1305, _, _>::new(
key,
&Default::default(), // please use a better nonce ;)
ArrayBuffer::<128>::new(),
&mut ciphertext,
)
.unwrap();
writer.write_all(plaintext)?;
writer.flush()?;
};
let mut decrypted = Vec::new();
{
let mut reader = DecryptBE32BufReader::<ChaCha20Poly1305, _, _>::new(
key,
ArrayBuffer::<256>::new(),
ciphertext.as_slice(),
)
.unwrap();
let _ = reader.read_to_end(&mut decrypted).unwrap();
};
assert_eq!(decrypted, plaintext);§no_std, array-buffer
This package is compatible with no_std environments. Just disable the default features! The
std Vec, io::Read and io::Write interfaces are reimplemented internally via
the Buffer, CappedBuffer,
ResizeBuffer, Write and
Read traits accordingly. There should be some default implementations
for Vec<u8>, byte slices and a no alloc compatible ArrayBuffer
if the array-buffer feature is enabled
Re-exports§
pub use aead;
Structs§
- Array
Buffer - A simple
no_stdcompatible Capped Buffer implementation - Decrypt
BufReader - A wrapper around a
Readobject and aStreamPrimitiveproviding aReadinterface which automatically decrypts the underlying stream when reading - Encrypt
BufWriter - A wrapper around a
Writeobject and aStreamPrimitiveproviding aWriteinterface which automatically encrypts the underlying stream when writing - Into
Inner Error - An error returned by
EncryptBufWriter::into_innerwhich combines an error that happened while writing out the buffer, and the buffered writer object which may be used to recover from the condition. - Invalid
Capacity - An error which occurs when providing an invalid buffer to a
BufReaderorBufWriter
Enums§
- Error
- An error for read/write operations with custom Error types. Mainly useful for
no_stdenvironments
Traits§
- Capped
Buffer - A trait for describing a buffer with a max capacity. Useful for
no_stdenvironments. Automatically implemented forVec<u8>whenallocenabled - Read
- Emulates
std::io::Readwith a simplified interface forno_stdenvironments. - Resize
Buffer - A trait for describing a buffer which can be resized. Useful for
no_stdenvironments. Automatically implemented forVec<u8>whenallocenabled - Write
- Emulates
std::io::Writewith a simplified interface forno_stdenvironments.
Type Aliases§
- DecryptB
E32Buf Reader - Convenience type for constructing a
BufReaderwith aStreamBE32 - DecryptL
E31Buf Reader - Convenience type for constructing a
BufReaderwith aStreamLE31 - EncryptB
E32Buf Writer - Convenience type for constructing a
BufWriterwith aStreamBE32 - EncryptL
E31Buf Writer - Convenience type for constructing a
BufWriterwith aStreamLE31