Struct sequoia_openpgp::serialize::stream::Recipient
source · pub struct Recipient<'a> { /* private fields */ }
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§
source§impl<'a> Recipient<'a>
impl<'a> Recipient<'a>
sourcepub fn new<P, R>(keyid: KeyID, key: &'a Key<P, R>) -> Recipient<'a>
pub fn new<P, R>(keyid: KeyID, key: &'a Key<P, R>) -> Recipient<'a>
Creates a new recipient with an explicit recipient keyid.
Note: If you don’t want to change the recipient keyid,
Recipient
s 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, Encryptor2,
};
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 = Encryptor2::for_recipients(message, recipients).build()?;
sourcepub fn keyid(&self) -> &KeyID
pub fn keyid(&self) -> &KeyID
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()?);
sourcepub fn set_keyid(self, keyid: KeyID) -> Self
pub fn set_keyid(self, keyid: KeyID) -> Self
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, Encryptor2,
};
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 = Encryptor2::for_recipients(message, recipients).build()?;