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>

source

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

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

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

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

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

Trait Implementations§

source§

impl<'a> Debug for Armorer<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Armorer<'a>

§

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

§

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

§

impl<'a> Sync for Armorer<'a>

§

impl<'a> Unpin for Armorer<'a>

§

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

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.