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

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

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

impl<'a> Recipient<'a>[src]

pub fn new<P, R>(keyid: KeyID, key: &'a Key<P, R>) -> Recipient<'a> where
    P: KeyParts,
    R: KeyRole
[src]

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).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()?;

pub fn keyid(&self) -> &KeyID[src]

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).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()?);

pub fn set_keyid(self, keyid: KeyID) -> Self[src]

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).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

impl<'a> Debug for Recipient<'a>[src]

impl<'a, P, R> From<&'a Key<P, R>> for Recipient<'a> where
    P: KeyParts,
    R: KeyRole
[src]

impl<'a, P, R, R2> From<ValidKeyAmalgamation<'a, P, R, R2>> for Recipient<'a> where
    P: KeyParts,
    R: KeyRole,
    R2: Copy
[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Recipient<'a>

impl<'a> Send for Recipient<'a>

impl<'a> Sync for Recipient<'a>

impl<'a> Unpin for Recipient<'a>

impl<'a> UnwindSafe for Recipient<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.