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

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

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

Methods

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

pub fn new(inner: Message<'a>) -> Self[src]

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

pub fn kind(self, kind: Kind) -> Self[src]

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

pub fn add_header<K, V>(self, key: K, value: V) -> Self where
    K: AsRef<str>,
    V: AsRef<str>, 
[src]

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

pub fn build(self) -> Result<Message<'a>>[src]

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

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

Auto Trait Implementations

impl<'a> !Send for Armorer<'a>

impl<'a> !Sync for Armorer<'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.