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
A simple no_std
compatible Capped Buffer implementation
A wrapper around a Read
object and a StreamPrimitive
providing a Read
interface which automatically decrypts the underlying stream when
reading
A wrapper around a Write
object and a StreamPrimitive
providing a Write
interface which automatically encrypts the underlying stream when
writing
An error returned by EncryptBufWriter::into_inner
which combines an error that happened
while writing out the buffer, and the buffered writer object which may be used to recover
from the condition.
Enums
An error for read/write operations with custom Error types. Mainly useful for no_std
environments
Traits
A trait for describing a buffer with a max capacity. Useful for no_std
environments.
Automatically implemented for Vec<u8>
when alloc
enabled
Emulates std::io::Read
with a simplified interface for no_std
environments.
A trait for describing a buffer which can be resized. Useful for no_std
environments.
Automatically implemented for Vec<u8>
when alloc
enabled
Emulates std::io::Write
with a simplified interface for no_std
environments.
Type Definitions
Convenience type for constructing a BufReader
with a StreamBE32
Convenience type for constructing a BufReader
with a StreamLE31
Convenience type for constructing a BufWriter
with a StreamBE32
Convenience type for constructing a BufWriter
with a StreamLE31