pub struct MdCtx(/* private fields */);
Implementations§
source§impl MdCtx
impl MdCtx
sourcepub fn new() -> Result<Self, ErrorStack>
pub fn new() -> Result<Self, ErrorStack>
Creates a new context.
This corresponds to EVP_MD_CTX_new
.
Methods from Deref<Target = MdCtxRef>§
sourcepub fn digest_init(&mut self, digest: &MdRef) -> Result<(), ErrorStack>
pub fn digest_init(&mut self, digest: &MdRef) -> Result<(), ErrorStack>
Initializes the context to compute the digest of data.
This corresponds to EVP_DigestInit_ex
.
sourcepub fn digest_sign_init<'a, T>(
&'a mut self,
digest: Option<&MdRef>,
pkey: &PKeyRef<T>
) -> Result<&'a mut PkeyCtxRef<T>, ErrorStack>where
T: HasPrivate,
pub fn digest_sign_init<'a, T>( &'a mut self, digest: Option<&MdRef>, pkey: &PKeyRef<T> ) -> Result<&'a mut PkeyCtxRef<T>, ErrorStack>where T: HasPrivate,
Initializes the context to compute the signature of data.
A reference to the context’s inner PkeyCtx
is returned, allowing signature settings to be configured.
This corresponds to EVP_DigestSignInit
.
sourcepub fn digest_verify_init<'a, T>(
&'a mut self,
digest: Option<&MdRef>,
pkey: &PKeyRef<T>
) -> Result<&'a mut PkeyCtxRef<T>, ErrorStack>where
T: HasPublic,
pub fn digest_verify_init<'a, T>( &'a mut self, digest: Option<&MdRef>, pkey: &PKeyRef<T> ) -> Result<&'a mut PkeyCtxRef<T>, ErrorStack>where T: HasPublic,
Initializes the context to verify the signature of data.
A reference to the context’s inner PkeyCtx
is returned, allowing signature settings to be configured.
This corresponds to EVP_DigestVerifyInit
.
sourcepub fn digest_update(&mut self, data: &[u8]) -> Result<(), ErrorStack>
pub fn digest_update(&mut self, data: &[u8]) -> Result<(), ErrorStack>
Updates the context with more data.
This corresponds to EVP_DigestUpdate
.
sourcepub fn digest_sign_update(&mut self, data: &[u8]) -> Result<(), ErrorStack>
pub fn digest_sign_update(&mut self, data: &[u8]) -> Result<(), ErrorStack>
Updates the context with more data.
This corresponds to EVP_DigestSignUpdate
.
sourcepub fn digest_verify_update(&mut self, data: &[u8]) -> Result<(), ErrorStack>
pub fn digest_verify_update(&mut self, data: &[u8]) -> Result<(), ErrorStack>
Updates the context with more data.
This corresponds to EVP_DigestVerifyUpdate
.
sourcepub fn digest_final(&mut self, out: &mut [u8]) -> Result<usize, ErrorStack>
pub fn digest_final(&mut self, out: &mut [u8]) -> Result<usize, ErrorStack>
Copies the computed digest into the buffer, returning the number of bytes written.
This corresponds to EVP_DigestFinal
.
sourcepub fn digest_final_xof(&mut self, out: &mut [u8]) -> Result<(), ErrorStack>
pub fn digest_final_xof(&mut self, out: &mut [u8]) -> Result<(), ErrorStack>
Copies the computed digest into the buffer.
Requires OpenSSL 1.1.1 or newer.
This corresponds to EVP_DigestFinalXOF
.
sourcepub fn digest_sign_final(
&mut self,
out: Option<&mut [u8]>
) -> Result<usize, ErrorStack>
pub fn digest_sign_final( &mut self, out: Option<&mut [u8]> ) -> Result<usize, ErrorStack>
Signs the computed digest.
If out
is set to None
, an upper bound on the number of bytes required for the output buffer will be
returned.
This corresponds to EVP_DigestSignFinal
.
sourcepub fn digest_sign_final_to_vec(
&mut self,
out: &mut Vec<u8>
) -> Result<usize, ErrorStack>
pub fn digest_sign_final_to_vec( &mut self, out: &mut Vec<u8> ) -> Result<usize, ErrorStack>
Like Self::digest_sign_final
but appends the signature to a Vec
.
sourcepub fn digest_verify_final(
&mut self,
signature: &[u8]
) -> Result<bool, ErrorStack>
pub fn digest_verify_final( &mut self, signature: &[u8] ) -> Result<bool, ErrorStack>
Verifies the provided signature.
Returns Ok(true)
if the signature is valid, Ok(false)
if the signature is invalid, and Err
if an error
occurred.
This corresponds to EVP_DigestVerifyFinal
.
sourcepub fn digest_sign(
&mut self,
from: &[u8],
to: Option<&mut [u8]>
) -> Result<usize, ErrorStack>
pub fn digest_sign( &mut self, from: &[u8], to: Option<&mut [u8]> ) -> Result<usize, ErrorStack>
Computes the signature of the data in from
.
If to
is set to None
, an upper bound on the number of bytes required for the output buffer will be
returned.
Requires OpenSSL 1.1.1 or newer.
This corresponds to EVP_DigestSign
.
sourcepub fn digest_sign_to_vec(
&mut self,
from: &[u8],
to: &mut Vec<u8>
) -> Result<usize, ErrorStack>
pub fn digest_sign_to_vec( &mut self, from: &[u8], to: &mut Vec<u8> ) -> Result<usize, ErrorStack>
Like Self::digest_sign
but appends the signature to a Vec
.
sourcepub fn digest_verify(
&mut self,
data: &[u8],
signature: &[u8]
) -> Result<bool, ErrorStack>
pub fn digest_verify( &mut self, data: &[u8], signature: &[u8] ) -> Result<bool, ErrorStack>
Verifies the signature of the data in data
.
Returns Ok(true)
if the signature is valid, Ok(false)
if the signature is invalid, and Err
if an error
occurred.
Requires OpenSSL 1.1.1 or newer.
This corresponds to EVP_DigestVerify
.
sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Returns the size of the message digest, i.e. the size of the hash
This corresponds to EVP_MD_CTX_size
.
sourcepub fn reset(&mut self) -> Result<(), ErrorStack>
pub fn reset(&mut self) -> Result<(), ErrorStack>
Resets the underlying EVP_MD_CTX instance
This corresponds to EVP_MD_CTX_reset
.