Skip to main content

Encryptor

Struct Encryptor 

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

Builder over rnp_op_encrypt_*. Configured first, then executed with Encryptor::build against the caller-supplied destination Output.

let plaintext = b"secret message";
let mut output = Output::to_memory().unwrap();
Encryptor::new(&ctx, plaintext).unwrap()
    .add_recipient(&key)
    .build(&mut output)
    .unwrap();
let _ciphertext = output.into_bytes().unwrap();

Implementations§

Source§

impl<'a> Encryptor<'a>

Source

pub fn new( ctx: &'a Context, plaintext: impl Into<MessageSource<'a>>, ) -> Result<Self>

Begin building an encryption operation over plaintext — anything message-shaped: a byte slice (b"...", &data[..]) or a caller-built Input (e.g. from Input::from_reader, to stream from a non-seekable source). The input is consumed when the operation executes.

Construction cannot fail (the source is only converted to an Input at execution time); the Result is kept for API stability.

Source

pub fn new_with_input(ctx: &'a Context, input: Input) -> Result<Self>

👎Deprecated since 0.2.0:

pass the Input to Encryptor::new; it accepts both

Begin building an encryption operation over a caller-built Input. Deprecated: pass the Input to Encryptor::new — it accepts both bytes and inputs.

Source

pub fn add_recipient(self, key: &'a Key<'a>) -> Self

Add a recipient’s public key. May be called multiple times.

Source

pub fn add_signature(self, key: &'a Key<'a>) -> Self

Add a signature key (sign-and-encrypt in one op). May be called multiple times.

Source

pub fn add_password( self, password: impl Into<Vec<u8>>, options: AddPasswordOptions, ) -> Self

Add a password-encrypted session key. May be called multiple times to allow multiple passwords (any one decrypts).

Source

pub fn armor(self, armored: bool) -> Self

Source

pub fn cipher(self, c: Cipher) -> Self

Source

pub fn hash(self, h: Hash) -> Self

Source

pub fn compression(self, alg: Compression, level: u32) -> Self

Source

pub fn aead(self, alg: AeadType) -> Self

Source

pub fn aead_bits(self, bits: i32) -> Self

AEAD chunk size in bits (0..=16 per the OpenPGP spec).

Source

pub fn file_name(self, name: impl AsRef<str>) -> Self

Source

pub fn file_mtime(self, mtime: u32) -> Self

Source

pub fn creation_time(self, t: u32) -> Self

Source

pub fn expiration_time(self, t: u32) -> Self

Source

pub fn flags(self, flags: EncryptFlags) -> Self

Source

pub fn prefer_pqc_enc_subkey(self) -> Self

Prefer PQC-encryption subkeys over non-PQC subkeys when choosing recipients. Feature-gated; requires --features pqc and a librnp built with ENABLE_PQC=ON.

Source

pub fn enable_pkesk_v6(self) -> Self

Enable v6 PKESK (Public-Key Encrypted Session Key) packets in the output. Feature-gated; requires --features crypto-refresh.

Source

pub fn enable_skesk_v6(self) -> Self

Enable v6 SKESK (Symmetric-Key Encrypted Session Key) packets in the output. Feature-gated; requires --features crypto-refresh.

Source

pub fn build(self, output: &mut Output) -> Result<()>

Execute the encryption, writing the ciphertext to output.

If a reader-backed input fails mid-operation, the returned error is the original std::io::Error (see Input::from_reader).

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Encryptor<'a>

§

impl<'a> !Send for Encryptor<'a>

§

impl<'a> !Sync for Encryptor<'a>

§

impl<'a> !UnwindSafe for Encryptor<'a>

§

impl<'a> Freeze for Encryptor<'a>

§

impl<'a> Unpin for Encryptor<'a>

§

impl<'a> UnsafeUnpin for Encryptor<'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 = !

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.