[][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.

Methods

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.

Example

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

     mQENBFpxtsABCADZcBa1Q3ZLZnju18o0+t8LoQuIIeyeUQ0H45y6xUqyrD5HSkVM
     ...
     -----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.

Example

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

     mQENBFpxtsABCADZcBa1Q3ZLZnju18o0+t8LoQuIIeyeUQ0H45y6xUqyrD5HSkVM
     ...
     -----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(),
           &"EA6E 3770 628A 713C".parse()?);

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

Sets the recipient keyid.

Example

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

     mQENBFpxtsABCADZcBa1Q3ZLZnju18o0+t8LoQuIIeyeUQ0H45y6xUqyrD5HSkVM
     ...
     -----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| {
        let mut r: Recipient = ka.into();
        // Set the recipient keyid to the wildcard id.
        r.set_keyid(KeyID::wildcard());
        r
    });

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

Trait Implementations

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]

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

Auto Trait Implementations

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

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

Blanket Implementations

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.