Renamed `reuse-buffer` to `ad-hoc-buffer`

Fortune for chacha20stream's current commit: Small curse − 小凶
read-stream-wrapper
Avril 3 years ago
parent 843616e35e
commit 30416382ec
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -28,10 +28,8 @@ async = ["tokio", "pin-project"]
# Explicitly clear in-memory buffers with `explicit_bzero()` instead of normal `bzero()`. # Explicitly clear in-memory buffers with `explicit_bzero()` instead of normal `bzero()`.
explicit_clear = [] explicit_clear = []
# Reuse the output buffer for `Source`'s raw bytes read from the backing stream # Use a stack (up to a max limit) allocated buffer for `Source`'s raw bytes read from the backing stream instead of a reused backing stream
# ad-hoc-buffer = []
# This can increase speed as no allocations are needed, however it can leak potentially sensitive data so is unsafe.
reuse-buffer = []
# Build with C interface bindings # Build with C interface bindings
ffi = ["libc"] ffi = ["libc"]

@ -100,9 +100,9 @@ impl BufferKind for UseBufferExternal
} }
} }
#[cfg(not(feature="reuse-buffer"))] #[cfg(not(feature="ad-hoc-buffer"))]
pub type DefaultBuffer = UseBufferInternal; pub type DefaultBuffer = UseBufferInternal;
#[cfg(feature="reuse-buffer")] #[cfg(feature="ad-hoc-buffer")]
pub type DefaultBuffer = UseBufferExternal; pub type DefaultBuffer = UseBufferExternal;
/// TODO: Document /// TODO: Document
@ -110,7 +110,7 @@ pub type DefaultBuffer = UseBufferExternal;
pub struct Source<R: ?Sized, Buffer: ?Sized + BufferKind = DefaultBuffer> pub struct Source<R: ?Sized, Buffer: ?Sized + BufferKind = DefaultBuffer>
{ {
crypter: Crypter, crypter: Crypter,
buffer: Buffer::InternalBuffer, // When `reuse-buffer` is enabled, this isn't needed. We re-use the output buffer for the initial read of untransformed data from `stream` and the actual transformation of the read bytes. buffer: Buffer::InternalBuffer, // When `ad-hoc-buffer` is enabled, this isn't needed. We re-use the output buffer for the initial read of untransformed data from `stream` and the actual transformation of the read bytes.
stream: R stream: R
} }
@ -232,7 +232,7 @@ impl<R> Source<R, UseBufferInternal>
} }
} }
fn try_alloca<T>(sz: usize, cb: impl FnOnce(&mut [u8]) -> T) -> T fn try_alloca<T>(sz: usize, cb: impl for<'a> FnOnce(&'a mut [u8]) -> T) -> T
{ {
if sz > STACK_MAX_BYTES { if sz > STACK_MAX_BYTES {
let mut bytes = vec![0u8; sz]; let mut bytes = vec![0u8; sz];
@ -246,7 +246,7 @@ impl<R: ?Sized, K: ?Sized + BufferKind> Read for Source<R, K>
where R: Read where R: Read
{ {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
if cfg!(feature="reuse-buffer") { if cfg!(feature="ad-hoc-buffer") {
//XXX: FUck, we can't `crypter.update()` in place.... //XXX: FUck, we can't `crypter.update()` in place....
try_alloca(buf.len(), move |temp| -> io::Result<usize> { try_alloca(buf.len(), move |temp| -> io::Result<usize> {

Loading…
Cancel
Save