Macro hard::buffer [−][src]
macro_rules! buffer { ($size:expr$(;)?) => { ... }; }
Expand description
Create a fixed-size anonymous buffer.
buffer!(Size) will initialise a new buffer of length Size bytes, returning
Result<Buffer, HardError>.
The buffer will implement the following traits:
BufferandBufferMutAsRef<[u8; Size]>andAsMut<[u8; Size]>Borrow<[u8; $size]>and [`BorrowMut<[u8;DebugDeref<Target = [u8; Size]>andDerefMut$size]>`](std::borrow::BorrowMut)PartialEq<Rhs = BufferMut or BufferReadOnly>andEq- This implementation uses a constant-time comparison function, suitable for comparing sensitive data without the risk of timing attacks.
Pointer
Example Usage
use hard::buffer; // Create a 32-byte buffer let mut some_buffer = buffer!(32).unwrap(); some_buffer.copy_from_slice(b"Copy this data into that buffer."); let mut another_buffer = buffer!(32).unwrap(); some_buffer.copy_from_slice(b"We'll compare these two buffers."); // This comparison is a constant-time equality-check of the contents of the two buffers assert!(some_buffer != another_buffer);