Skip to main content

EncryptBuffer

Struct EncryptBuffer 

Source
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>

Source

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.

Source

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).

Source

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).

Source

pub fn into_written(self) -> &'a [u8]

Consume this value, returning the written prefix of the wrapped buffer.

Trait Implementations§

Source§

impl AsMut<[u8]> for EncryptBuffer<'_>

Source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for EncryptBuffer<'a>

§

impl<'a> Freeze for EncryptBuffer<'a>

§

impl<'a> RefUnwindSafe for EncryptBuffer<'a>

§

impl<'a> Send for EncryptBuffer<'a>

§

impl<'a> Sync for EncryptBuffer<'a>

§

impl<'a> Unpin for EncryptBuffer<'a>

§

impl<'a> UnsafeUnpin for EncryptBuffer<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more