Decrypter

Struct Decrypter 

Source
pub struct Decrypter<'a> { /* private fields */ }
Expand description

A type which decrypts data.

Implementations§

Source§

impl<'a> Decrypter<'a>

Source

pub fn new<T>(pkey: &'a PKeyRef<T>) -> Result<Decrypter<'a>, ErrorStack>
where T: HasPrivate,

Creates a new Decrypter.

OpenSSL documentation at EVP_PKEY_decrypt_init.

Source

pub fn rsa_padding(&self) -> Result<Padding, ErrorStack>

Returns the RSA padding mode in use.

This is only useful for RSA keys.

This corresponds to EVP_PKEY_CTX_get_rsa_padding.

Source

pub fn set_rsa_padding(&mut self, padding: Padding) -> Result<(), ErrorStack>

Sets the RSA padding mode.

This is only useful for RSA keys.

This corresponds to EVP_PKEY_CTX_set_rsa_padding.

Source

pub fn set_rsa_mgf1_md(&mut self, md: MessageDigest) -> Result<(), ErrorStack>

Sets the RSA MGF1 algorithm.

This is only useful for RSA keys.

This corresponds to EVP_PKEY_CTX_set_rsa_mgf1_md.

Source

pub fn set_rsa_oaep_md(&mut self, md: MessageDigest) -> Result<(), ErrorStack>

Sets the RSA OAEP algorithm.

This is only useful for RSA keys.

This corresponds to EVP_PKEY_CTX_set_rsa_oaep_md.

Source

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

Sets the RSA OAEP label.

This is only useful for RSA keys.

This corresponds to EVP_PKEY_CTX_set0_rsa_oaep_label.

Source

pub fn decrypt(&self, from: &[u8], to: &mut [u8]) -> Result<usize, ErrorStack>

Performs public key decryption.

In order to know the size needed for the output buffer, use decrypt_len. Note that the length of the output buffer can be greater of the length of the decoded data.

let mut decrypter = Decrypter::new(&pkey).unwrap();
decrypter.set_rsa_padding(Padding::PKCS1).unwrap();

// Get the length of the output buffer
let buffer_len = decrypter.decrypt_len(&input).unwrap();
let mut decoded = vec![0u8; buffer_len];

// Decrypt the data and get its length
let decoded_len = decrypter.decrypt(&input, &mut decoded).unwrap();

// Use only the part of the buffer with the decrypted data
let decoded = &decoded[..decoded_len];

This corresponds to EVP_PKEY_decrypt.

Source

pub fn decrypt_len(&self, from: &[u8]) -> Result<usize, ErrorStack>

Gets the size of the buffer needed to decrypt the input data.

This corresponds to EVP_PKEY_decrypt called with a null pointer as output argument.

Trait Implementations§

Source§

impl Drop for Decrypter<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Decrypter<'_>

Source§

impl Sync for Decrypter<'_>

Auto Trait Implementations§

§

impl<'a> Freeze for Decrypter<'a>

§

impl<'a> RefUnwindSafe for Decrypter<'a>

§

impl<'a> Unpin for Decrypter<'a>

§

impl<'a> UnwindSafe for Decrypter<'a>

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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 8 bytes