diff --git a/block-buffer/src/lib.rs b/block-buffer/src/lib.rs index d3b69165..fea3262b 100644 --- a/block-buffer/src/lib.rs +++ b/block-buffer/src/lib.rs @@ -55,12 +55,12 @@ impl> BlockBuffer { self.pos += input.len(); } - /* /// Process data in `input` in blocks of size `BlockSize` using function `f`, which accepts /// slice of blocks. #[inline] pub fn input2(&mut self, mut input: &[u8], mut f: F) - where F: FnMut(&[GenericArray]) + where + F: FnMut(&[GenericArray]), { // If there is already data in the buffer, process it if we have // enough to complete the chunk. @@ -70,14 +70,18 @@ impl> BlockBuffer { input = r; self.buffer[self.pos..].copy_from_slice(l); self.pos = 0; - f(slice::from_ref(&self.buffer)); + // TODO: once MSRV is up to 1.28.0 use `slice::from_ref`. + f(unsafe { + // Safe becuase this matches the implementation in the std lib. + slice::from_raw_parts(&self.buffer, 1) + }); } // While we have at least a full buffer size chunks's worth of data, // process it data without copying into the buffer - let n_blocks = input.len()/self.size(); - let (left, right) = input.split_at(n_blocks*self.size()); - // safe because we guarantee that `blocks` does not point outside of `input` + let n_blocks = input.len() / self.size(); + let (left, right) = input.split_at(n_blocks * self.size()); + // safe because we guarantee that `blocks` does not point outside of `input` let blocks = unsafe { slice::from_raw_parts( left.as_ptr() as *const GenericArray, @@ -87,10 +91,9 @@ impl> BlockBuffer { f(blocks); // Copy remaining data into the buffer. - self.buffer[self.pos..self.pos+right.len()].copy_from_slice(right); + self.buffer[self.pos..self.pos + right.len()].copy_from_slice(right); self.pos += right.len(); } - */ /// Variant that doesn't flush the buffer until there's additional /// data to be processed. Suitable for tweakable block ciphers