Struct sequoia_openpgp::serialize::stream::Armorer
source · pub struct Armorer<'a> { /* private fields */ }
Expand description
Applies ASCII Armor to the message.
ASCII armored data (see Section 6 of RFC 4880) is a OpenPGP data stream that has been base64-encoded and decorated with a header, footer, and optional headers representing key-value pairs. It can be safely transmitted over protocols that can only transmit printable characters, and can handled by end users (e.g. copied and pasted).
Implementations§
source§impl<'a> Armorer<'a>
impl<'a> Armorer<'a>
sourcepub fn new(inner: Message<'a>) -> Self
pub fn new(inner: Message<'a>) -> Self
Creates a new armoring filter.
By default, the type of the armored data is set to
armor::Kind
::Message
. To change it, use
Armorer::kind
. To add headers to the armor, use
Armorer::add_header
.
§Examples
use std::io::Write;
use sequoia_openpgp as openpgp;
use openpgp::serialize::stream::{Message, Armorer, LiteralWriter};
let mut sink = vec![];
{
let message = Message::new(&mut sink);
let message = Armorer::new(message)
// Customize the `Armorer` here.
.build()?;
let mut message = LiteralWriter::new(message).build()?;
message.write_all(b"Hello world.")?;
message.finalize()?;
}
assert_eq!("-----BEGIN PGP MESSAGE-----\n\
\n\
yxJiAAAAAABIZWxsbyB3b3JsZC4=\n\
=6nHv\n\
-----END PGP MESSAGE-----\n",
std::str::from_utf8(&sink)?);
sourcepub fn kind(self, kind: Kind) -> Self
pub fn kind(self, kind: Kind) -> Self
Changes the kind of armoring.
The armor header and footer changes depending on the type of
wrapped data. See armor::Kind
for the possible values.
§Examples
use std::io::Write;
use sequoia_openpgp as openpgp;
use openpgp::armor;
use openpgp::serialize::stream::{Message, Armorer, Signer};
let mut sink = vec![];
{
let message = Message::new(&mut sink);
let message = Armorer::new(message)
.kind(armor::Kind::Signature)
.build()?;
let mut signer = Signer::new(message, signing_keypair)
.detached()
.build()?;
// Write the data directly to the `Signer`.
signer.write_all(b"Make it so, number one!")?;
// In reality, just io::copy() the file to be signed.
signer.finalize()?;
}
assert!(std::str::from_utf8(&sink)?
.starts_with("-----BEGIN PGP SIGNATURE-----\n"));
sourcepub fn add_header<K, V>(self, key: K, value: V) -> Self
pub fn add_header<K, V>(self, key: K, value: V) -> Self
Adds a header to the armor block.
There are a number of defined armor header keys (see Section 6 of RFC 4880), but in practice, any key may be used, as implementations should simply ignore unknown keys.
§Examples
use std::io::Write;
use sequoia_openpgp as openpgp;
use openpgp::serialize::stream::{Message, Armorer, LiteralWriter};
let mut sink = vec![];
{
let message = Message::new(&mut sink);
let message = Armorer::new(message)
.add_header("Comment", "No comment.")
.build()?;
let mut message = LiteralWriter::new(message).build()?;
message.write_all(b"Hello world.")?;
message.finalize()?;
}
assert_eq!("-----BEGIN PGP MESSAGE-----\n\
Comment: No comment.\n\
\n\
yxJiAAAAAABIZWxsbyB3b3JsZC4=\n\
=6nHv\n\
-----END PGP MESSAGE-----\n",
std::str::from_utf8(&sink)?);
sourcepub fn build(self) -> Result<Message<'a>>
pub fn build(self) -> Result<Message<'a>>
Builds the armor writer, returning the writer stack.
§Examples
use sequoia_openpgp as openpgp;
use openpgp::serialize::stream::{Message, Armorer, LiteralWriter};
let message = Message::new(&mut sink);
let message = Armorer::new(message)
// Customize the `Armorer` here.
.build()?;