Struct sequoia_openpgp::serialize::stream::Recipient[][src]

pub struct Recipient<'a> { /* fields omitted */ }
Expand description

A recipient of an encrypted message.

OpenPGP messages are encrypted with the subkeys of recipients, identified by the keyid of said subkeys in the recipient field of PKESK packets (see Section 5.1 of RFC 4880). The keyid may be a wildcard (as returned by KeyID::wildcard()) to obscure the identity of the recipient.

Note that several subkeys in a certificate may be suitable encryption subkeys. OpenPGP does not specify what should happen in this case. Some implementations arbitrarily pick one encryption subkey, while others use all of them. This crate does not dictate a policy, but allows for arbitrary policies. We do, however, suggest to encrypt to all suitable subkeys.

Implementations

Creates a new recipient with an explicit recipient keyid.

Note: If you don’t want to change the recipient keyid, Recipients can be created from Key and ValidKeyAmalgamation using From.

Examples
use std::io::Write;
use sequoia_openpgp as openpgp;
use openpgp::cert::prelude::*;
use openpgp::serialize::stream::{
    Recipient, Message, Encryptor,
};
use openpgp::policy::StandardPolicy;

let p = &StandardPolicy::new();

let cert = Cert::from_bytes(
    "-----BEGIN PGP PUBLIC KEY BLOCK-----

     xjMEWlNvABYJKwYBBAHaRw8BAQdA+EC2pvebpEbzPA9YplVgVXzkIG5eK+7wEAez
     ...
     -----END PGP PUBLIC KEY BLOCK-----"
)?;

let recipients =
    cert.keys().with_policy(p, None).supported().alive().revoked(false)
    // Or `for_storage_encryption()`, for data at rest.
    .for_transport_encryption()
    .map(|ka| Recipient::new(ka.key().keyid(), ka.key()));

let message = Message::new(&mut sink);
let message = Encryptor::for_recipients(message, recipients).build()?;

Gets the recipient keyid.

Examples
use std::io::Write;
use sequoia_openpgp as openpgp;
use openpgp::cert::prelude::*;
use openpgp::serialize::stream::Recipient;
use openpgp::policy::StandardPolicy;

let p = &StandardPolicy::new();

let cert = Cert::from_bytes(
    "-----BEGIN PGP PUBLIC KEY BLOCK-----

     xjMEWlNvABYJKwYBBAHaRw8BAQdA+EC2pvebpEbzPA9YplVgVXzkIG5eK+7wEAez
     ...
     -----END PGP PUBLIC KEY BLOCK-----"
)?;

let recipients =
    cert.keys().with_policy(p, None).supported().alive().revoked(false)
    // Or `for_storage_encryption()`, for data at rest.
    .for_transport_encryption()
    .map(Into::into)
    .collect::<Vec<Recipient>>();

assert_eq!(recipients[0].keyid(),
           &"8BD8 8E94 C0D2 0333".parse()?);

Sets the recipient keyid.

Examples
use std::io::Write;
use sequoia_openpgp as openpgp;
use openpgp::KeyID;
use openpgp::cert::prelude::*;
use openpgp::serialize::stream::{
    Recipient, Message, Encryptor,
};
use openpgp::policy::StandardPolicy;

let p = &StandardPolicy::new();

let cert = Cert::from_bytes(
    "-----BEGIN PGP PUBLIC KEY BLOCK-----

     xjMEWlNvABYJKwYBBAHaRw8BAQdA+EC2pvebpEbzPA9YplVgVXzkIG5eK+7wEAez
     ...
     -----END PGP PUBLIC KEY BLOCK-----"
)?;

let recipients =
    cert.keys().with_policy(p, None).supported().alive().revoked(false)
    // Or `for_storage_encryption()`, for data at rest.
    .for_transport_encryption()
    .map(|ka| Recipient::from(ka)
        // Set the recipient keyid to the wildcard id.
        .set_keyid(KeyID::wildcard())
    );

let message = Message::new(&mut sink);
let message = Encryptor::for_recipients(message, recipients).build()?;

Trait Implementations

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.