pub struct Deriver<'a>(/* private fields */);
Expand description
A type used to derive a shared secret between two keys.
Implementations§
source§impl<'a> Deriver<'a>
impl<'a> Deriver<'a>
sourcepub fn new<T>(key: &'a PKeyRef<T>) -> Result<Deriver<'a>, ErrorStack>where
T: HasPrivate,
pub fn new<T>(key: &'a PKeyRef<T>) -> Result<Deriver<'a>, ErrorStack>where
T: HasPrivate,
Creates a new Deriver
using the provided private key.
This corresponds to EVP_PKEY_derive_init
.
sourcepub fn set_peer<T>(&mut self, key: &'a PKeyRef<T>) -> Result<(), ErrorStack>where
T: HasPublic,
pub fn set_peer<T>(&mut self, key: &'a PKeyRef<T>) -> Result<(), ErrorStack>where
T: HasPublic,
Sets the peer key used for secret derivation.
This corresponds to EVP_PKEY_derive_set_peer
.
sourcepub fn set_peer_ex<T>(
&mut self,
key: &'a PKeyRef<T>,
validate_peer: bool,
) -> Result<(), ErrorStack>where
T: HasPublic,
pub fn set_peer_ex<T>(
&mut self,
key: &'a PKeyRef<T>,
validate_peer: bool,
) -> Result<(), ErrorStack>where
T: HasPublic,
Sets the peer key used for secret derivation along with optionally validating the peer public key.
Requires OpenSSL 3.0.0 or newer.
This corresponds to EVP_PKEY_derive_set_peer_ex
.
sourcepub fn len(&mut self) -> Result<usize, ErrorStack>
pub fn len(&mut self) -> Result<usize, ErrorStack>
Returns the size of the shared secret.
It can be used to size the buffer passed to Deriver::derive
.
This corresponds to EVP_PKEY_derive
.
sourcepub fn derive(&mut self, buf: &mut [u8]) -> Result<usize, ErrorStack>
pub fn derive(&mut self, buf: &mut [u8]) -> Result<usize, ErrorStack>
Derives a shared secret between the two keys, writing it into the buffer.
Returns the number of bytes written.
This corresponds to EVP_PKEY_derive
.
sourcepub fn derive_to_vec(&mut self) -> Result<Vec<u8>, ErrorStack>
pub fn derive_to_vec(&mut self) -> Result<Vec<u8>, ErrorStack>
A convenience function which derives a shared secret and returns it in a new buffer.
This simply wraps Deriver::len
and Deriver::derive
.