diff --git a/Cargo.toml b/Cargo.toml index 8694982..9120224 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,10 +28,8 @@ async = ["tokio", "pin-project"] # Explicitly clear in-memory buffers with `explicit_bzero()` instead of normal `bzero()`. explicit_clear = [] -# Reuse the output buffer for `Source`'s raw bytes read from the backing stream -# -# This can increase speed as no allocations are needed, however it can leak potentially sensitive data so is unsafe. -reuse-buffer = [] +# 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 = [] # Build with C interface bindings ffi = ["libc"] diff --git a/src/stream/source.rs b/src/stream/source.rs index 83895a0..1412c55 100644 --- a/src/stream/source.rs +++ b/src/stream/source.rs @@ -100,9 +100,9 @@ impl BufferKind for UseBufferExternal } } -#[cfg(not(feature="reuse-buffer"))] +#[cfg(not(feature="ad-hoc-buffer"))] pub type DefaultBuffer = UseBufferInternal; -#[cfg(feature="reuse-buffer")] +#[cfg(feature="ad-hoc-buffer")] pub type DefaultBuffer = UseBufferExternal; /// TODO: Document @@ -110,7 +110,7 @@ pub type DefaultBuffer = UseBufferExternal; pub struct Source { 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 } @@ -232,7 +232,7 @@ impl Source } } -fn try_alloca(sz: usize, cb: impl FnOnce(&mut [u8]) -> T) -> T +fn try_alloca(sz: usize, cb: impl for<'a> FnOnce(&'a mut [u8]) -> T) -> T { if sz > STACK_MAX_BYTES { let mut bytes = vec![0u8; sz]; @@ -246,7 +246,7 @@ impl Read for Source where R: Read { fn read(&mut self, buf: &mut [u8]) -> io::Result { - if cfg!(feature="reuse-buffer") { + if cfg!(feature="ad-hoc-buffer") { //XXX: FUck, we can't `crypter.update()` in place.... try_alloca(buf.len(), move |temp| -> io::Result {