pub struct EncryptBuffer<'a> { /* private fields */ }Expand description
A fixed-size buffer into which a MessageEncrypter writes an encrypted message payload.
This wraps the output buffer passed to MessageEncrypter::encrypt(), tracking how
much of it has been written as the append methods fill it front-to-back. It writes
into caller-owned memory and cannot grow. Self::new() checks that the caller’s
buffer can hold the len bytes the encrypter declared, and the append methods then
panic if the writes exceed that length.
Such a panic always indicates a bug in the MessageEncrypter implementation, not a
runtime condition the caller can handle. The same implementation declares the total
length up front (via MessageEncrypter::encrypted_payload_len()) and performs the
writes, so overflowing the buffer means the two disagree. The record layer also
relies on that declared length for framing, so there is no way to recover from the
mismatch after the fact.
Implementations§
Source§impl<'a> EncryptBuffer<'a>
impl<'a> EncryptBuffer<'a>
Sourcepub fn new(out: &'a mut [u8], len: usize) -> Result<Self, Error>
pub fn new(out: &'a mut [u8], len: usize) -> Result<Self, Error>
Wrap the first len bytes of out, all of which are as yet unwritten.
Returns ApiMisuse::EncryptBufferTooSmall if out is shorter than len bytes.
Sourcepub fn extend_from_chunks(&mut self, chunks: &OutboundPlain<'_>)
pub fn extend_from_chunks(&mut self, chunks: &OutboundPlain<'_>)
Append bytes from an OutboundPlain’s chunks.
Panics if the write would extend beyond the len given to Self::new(),
which indicates a bug in the calling MessageEncrypter implementation (see
the type-level documentation).
Sourcepub fn extend_from_slice(&mut self, slice: &[u8])
pub fn extend_from_slice(&mut self, slice: &[u8])
Append bytes from a slice.
Panics if the write would extend beyond the len given to Self::new(),
which indicates a bug in the calling MessageEncrypter implementation (see
the type-level documentation).
Sourcepub fn into_written(self) -> &'a [u8] ⓘ
pub fn into_written(self) -> &'a [u8] ⓘ
Consume this value, returning the written prefix of the wrapped buffer.