embassy-crypto

Crates

git

Versions

default

Flavors

Skip to main content

InOutBuf

Struct InOutBuf 

Source
pub struct InOutBuf<'inp, 'out, T> { /* private fields */ }
Expand description

A buffer that is read from and written to, which may or may not alias.

Drivers receive one of these for every cipher operation, covering both the in-place case (one buffer, encrypted in place) and the separate-buffer case (plaintext in one buffer, ciphertext to another) with a single entry point.

Implementations§

Source§

impl<'inp, 'out, T> InOutBuf<'inp, 'out, T>

Source

pub fn new( in_buf: &'inp [T], out_buf: &'out mut [T], ) -> Result<Self, NotEqualError>

Create an in/out buffer from separate input and output slices of equal length.

Source

pub unsafe fn from_raw(in_ptr: *const T, out_ptr: *mut T, len: usize) -> Self

Construct from raw pointers.

§Safety

in_ptr must be valid for reads and out_ptr for writes of len elements for the respective lifetimes. They may be equal; otherwise the regions must not overlap.

Source

pub fn get_in(&self) -> &[T]

The input side.

Source

pub fn get_out(&mut self) -> &mut [T]

The output side.

Source

pub fn is_in_place(&self) -> bool

Whether the input and output are the same buffer.

Source

pub unsafe fn split(self) -> (&'inp [T], &'out mut [T])

Split into the input and output slices.

When the buffer is in place, the returned slices alias. This is not exposed as safe API for that reason; use get_in, get_out or into_out_with_copied_in.

§Safety

The caller must not use both slices when is_in_place.

Source

pub fn into_out_with_copied_in(self) -> &'out mut [T]
where T: Copy,

Return the output slice, after copying the input into it when they differ.

The natural entry point for drivers that only operate in place.

Source

pub fn reborrow_range( &mut self, start: usize, end: usize, ) -> InOutBuf<'_, '_, T>

Reborrow a sub-range of the buffer.

Source

pub fn into_raw(self) -> (*const T, *mut T)

Consume the buffer and return the raw pointers.

Source

pub fn len(&self) -> usize

Length of the buffer.

Source

pub fn is_empty(&self) -> bool

Whether the buffer is empty.

Trait Implementations§

Source§

impl<'a, T> From<&'a mut [T]> for InOutBuf<'a, 'a, T>

Source§

fn from(buf: &'a mut [T]) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'inp, 'out, T> !Send for InOutBuf<'inp, 'out, T>

§

impl<'inp, 'out, T> !Sync for InOutBuf<'inp, 'out, T>

§

impl<'inp, 'out, T> !UnwindSafe for InOutBuf<'inp, 'out, T>

§

impl<'inp, 'out, T> Freeze for InOutBuf<'inp, 'out, T>

§

impl<'inp, 'out, T> RefUnwindSafe for InOutBuf<'inp, 'out, T>

§

impl<'inp, 'out, T> Unpin for InOutBuf<'inp, 'out, T>

§

impl<'inp, 'out, T> UnsafeUnpin for InOutBuf<'inp, 'out, T>

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.

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 = !

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.