Skip to main content

DigestCtx

Struct DigestCtx 

Source
pub struct DigestCtx { /* private fields */ }
Expand description

Stateful hash context (EVP_MD_CTX*).

!Clone — use fork() to duplicate mid-stream state. All stateful operations require &mut self (exclusive ownership).

Implementations§

Source§

impl DigestCtx

Source

pub fn update(&mut self, data: &[u8]) -> Result<(), ErrorStack>

Feed data into the ongoing hash computation.

§Errors

Returns Err if EVP_DigestUpdate fails.

Source

pub fn finish(&mut self, out: &mut [u8]) -> Result<usize, ErrorStack>

Finalise the hash and write the result into out.

out must be at least alg.output_len() bytes. Returns the number of bytes written.

§Errors

Returns Err if EVP_DigestFinal_ex fails.

Source

pub fn finish_xof(&mut self, out: &mut [u8]) -> Result<(), ErrorStack>

Finalise with XOF (extendable-output) mode.

Used by SHAKE-128, SHAKE-256. out.len() determines the output length.

§Errors
Source

pub fn fork(&self) -> Result<DigestCtx, ErrorStack>

Fork the current mid-stream state into a new context.

Equivalent to EVP_MD_CTX_copy_ex — a deep copy of the context state. Named fork (not clone) to signal the operation is potentially expensive.

§Errors
Source

pub fn new_empty() -> Result<Self, ErrorStack>

Allocate an uninitialised EVP_MD_CTX.

The context is not associated with any algorithm yet. Use this when a raw context handle is needed before a higher-level init call (e.g. EVP_DigestSignInit_ex).

§Errors

Returns Err if EVP_MD_CTX_new fails.

Source

pub fn reinit( &mut self, alg: &DigestAlg, params: Option<&Params<'_>>, ) -> Result<(), ErrorStack>

Reinitialise this context for reuse with the given algorithm.

Calls EVP_DigestInit_ex2. Pass None for params when no extra initialisation parameters are required.

§Errors

Returns Err if EVP_DigestInit_ex2 fails.

Source

pub unsafe fn from_ptr(ptr: *mut EVP_MD_CTX) -> Self

Construct a DigestCtx from a raw, owned EVP_MD_CTX*.

§Safety

ptr must be a valid, non-null EVP_MD_CTX* that the caller is giving up ownership of. The context need not be initialised with a digest algorithm yet.

Source

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

Return the raw EVP_MD_CTX* pointer. Valid for the lifetime of self.

Used by Signer/Verifier which call EVP_DigestSign* on this context directly. Returns a mutable pointer because most OpenSSL EVP functions require EVP_MD_CTX* even for logically read-only operations.

Trait Implementations§

Source§

impl Debug for DigestCtx

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for DigestCtx

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for DigestCtx

Source§

impl Sync for DigestCtx

Auto Trait Implementations§

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.