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>
impl<'a> Encryptor<'a>
Sourcepub fn new(
ctx: &'a Context,
plaintext: impl Into<MessageSource<'a>>,
) -> Result<Self>
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.
Sourcepub 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
pub fn new_with_input(ctx: &'a Context, input: Input) -> Result<Self>
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.
Sourcepub fn add_recipient(self, key: &'a Key<'a>) -> Self
pub fn add_recipient(self, key: &'a Key<'a>) -> Self
Add a recipient’s public key. May be called multiple times.
Sourcepub fn add_signature(self, key: &'a Key<'a>) -> Self
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.
Sourcepub fn add_password(
self,
password: impl Into<Vec<u8>>,
options: AddPasswordOptions,
) -> Self
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).
pub fn armor(self, armored: bool) -> Self
pub fn cipher(self, c: Cipher) -> Self
pub fn hash(self, h: Hash) -> Self
pub fn compression(self, alg: Compression, level: u32) -> Self
pub fn aead(self, alg: AeadType) -> Self
Sourcepub fn aead_bits(self, bits: i32) -> Self
pub fn aead_bits(self, bits: i32) -> Self
AEAD chunk size in bits (0..=16 per the OpenPGP spec).
pub fn file_name(self, name: impl AsRef<str>) -> Self
pub fn file_mtime(self, mtime: u32) -> Self
pub fn creation_time(self, t: u32) -> Self
pub fn expiration_time(self, t: u32) -> Self
pub fn flags(self, flags: EncryptFlags) -> Self
Sourcepub fn prefer_pqc_enc_subkey(self) -> Self
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.
Sourcepub fn enable_pkesk_v6(self) -> Self
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.
Sourcepub fn enable_skesk_v6(self) -> Self
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.
Sourcepub fn build(self, output: &mut Output) -> Result<()>
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).