Struct vodozemac::pk_encryption::PkDecryption

source ·
pub struct PkDecryption { /* private fields */ }
Expand description

The decryption component of the PkEncryption support.

The public key can be shared with others, allowing them to encrypt messages which can be decrypted using the corresponding private key.

Implementations§

source§

impl PkDecryption

source

pub fn new() -> Self

Create a new random PkDecryption object.

This contains a fresh Curve25519SecretKey which is used as a long-term key to derive individual message keys and effectively serves as the decryption secret.

source

pub fn from_key(secret_key: Curve25519SecretKey) -> Self

Create a PkDecryption object from a Curve25519SecretKey key.

The Curve25519SecretKey will be used as the long-term key to derive individual message keys.

source

pub const fn secret_key(&self) -> &Curve25519SecretKey

Get the Curve25519SecretKey of this PkDecryption object.

If persistence is required, securely serialize and store this key. It can be used to reconstruct the PkDecryption object for decrypting associated messages.

source

pub const fn public_key(&self) -> Curve25519PublicKey

Get the associated ephemeral Curve25519PublicKey. This key can be used to reconstruct the PkEncryption object to encrypt messages.

source

pub fn from_libolm_pickle( pickle: &str, pickle_key: &[u8], ) -> Result<Self, LibolmPickleError>

Create a PkDecryption object by unpickling a PkDecryption pickle in libolm legacy pickle format.

Such pickles are encrypted and need to first be decrypted using a pickle_key.

source

pub fn to_libolm_pickle( &self, pickle_key: &[u8], ) -> Result<String, LibolmPickleError>

Pickle a PkDecryption into a libolm pickle format.

This pickle can be restored using the [PkDecryption::from_libolm_pickle] method, or can be used in the libolm C library.

The pickle will be encrypted using the pickle key.

⚠️ Security Warning: The pickle key will get expanded into both an AES key and an IV in a deterministic manner. If the same pickle key is reused, this will lead to IV reuse. To prevent this, users have to ensure that they always use a globally (probabilistically) unique pickle key.

§Examples
use vodozemac::pk_encryption::PkDecryption;
use olm_rs::{pk::OlmPkDecryption, PicklingMode};

let decrypt = PkDecryption::new();

let pickle = decrypt
    .to_libolm_pickle(&[0u8; 32])
    .expect("We should be able to pickle a freshly created PkDecryption");

let unpickled = OlmPkDecryption::unpickle(
    pickle,
    PicklingMode::Encrypted { key: [0u8; 32].to_vec() },
).expect("We should be able to unpickle our exported PkDecryption");
source

pub fn decrypt(&self, message: &Message) -> Result<Vec<u8>, Error>

Decrypt a Message which was encrypted for this PkDecryption object.

Trait Implementations§

source§

impl Default for PkDecryption

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<&PkDecryption> for PkEncryption

source§

fn from(value: &PkDecryption) -> Self

Converts to this type from the input type.

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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V