Skip to main content

CipherCtx

Struct CipherCtx 

Source
pub struct CipherCtx<Dir> { /* private fields */ }
Expand description

Stateful symmetric cipher context.

Dir is either Encrypt or Decrypt; the type parameter prevents accidentally calling encrypt operations on a decrypt context and vice versa.

!Clone — cipher contexts have no up_ref; use a fresh context per message.

Implementations§

Source§

impl<Dir: Direction> CipherCtx<Dir>

Source

pub fn update( &mut self, input: &[u8], output: &mut [u8], ) -> Result<usize, ErrorStack>
where Dir: IsEncrypt,

Feed input into the cipher; write plaintext/ciphertext to output.

output must be at least input.len() + block_size - 1 bytes. Returns the number of bytes written.

§Errors
Source

pub fn update_to_vec(&mut self, input: &[u8]) -> Result<Vec<u8>, ErrorStack>
where Dir: IsEncrypt,

Feed input through the cipher and return the output as a Vec<u8>.

Allocates input.len() + block_size bytes, calls Self::update, then truncates to the actual number of bytes written. Use this when the caller cannot easily compute the output size in advance.

§Errors
Source

pub fn finalize(&mut self, output: &mut [u8]) -> Result<usize, ErrorStack>
where Dir: IsEncrypt,

Finalise the operation (flush padding / verify auth tag).

§Errors
Source

pub fn set_params(&mut self, params: &Params<'_>) -> Result<(), ErrorStack>

Set dynamic parameters on the context (e.g. GCM tag length).

§Errors
Source

pub fn as_ptr(&self) -> *mut EVP_CIPHER_CTX

Return the raw EVP_CIPHER_CTX* pointer. Returns a mutable pointer because most OpenSSL EVP functions require EVP_CIPHER_CTX* even for logically read-only operations.

Trait Implementations§

Source§

impl<Dir> Drop for CipherCtx<Dir>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<Dir: Direction> Send for CipherCtx<Dir>

Auto Trait Implementations§

§

impl<Dir> Freeze for CipherCtx<Dir>

§

impl<Dir> RefUnwindSafe for CipherCtx<Dir>
where Dir: RefUnwindSafe,

§

impl<Dir> !Sync for CipherCtx<Dir>

§

impl<Dir> Unpin for CipherCtx<Dir>
where Dir: Unpin,

§

impl<Dir> UnsafeUnpin for CipherCtx<Dir>

§

impl<Dir> UnwindSafe for CipherCtx<Dir>
where Dir: UnwindSafe,

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