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

pub struct Armorer<'a> { /* fields omitted */ }
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

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

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"));

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

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

Trait Implementations

Formats the value using the given formatter. Read more

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.