vodozemac::pk_encryption

Struct 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

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V