[][src]Struct sequoia_openpgp::armor::Reader

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

A filter that strips ASCII Armor from a stream of data.

Implementations

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

pub fn new<R, M>(inner: R, mode: M) -> Self where
    R: 'a + Read,
    M: Into<Option<ReaderMode>>, 
[src]

Constructs a new filter for the given type of data.

ASCII Armor, designed to protect OpenPGP data in transit, has been a source of problems if the armor structure is damaged. For example, copying data manually from one program to another might introduce or drop newlines.

By default, the reader operates in robust mode. It will extract the first armored OpenPGP data block it can find, even if the armor frame is damaged, or missing.

To select strict mode, specify a kind argument. In strict mode, the reader will match on the armor frame. The reader ignores any data in front of the Armor Header Line, as long as the line the header is only prefixed by whitespace.

Examples

use std::io::{self, Read};
use sequoia_openpgp as openpgp;
use openpgp::Message;
use openpgp::armor::{Reader, ReaderMode};
use openpgp::parse::Parse;

let data = "yxJiAAAAAABIZWxsbyB3b3JsZCE="; // base64 over literal data packet

let mut cursor = io::Cursor::new(&data);
let mut reader = Reader::new(&mut cursor, ReaderMode::VeryTolerant);

let mut buf = Vec::new();
reader.read_to_end(&mut buf)?;

let message = Message::from_bytes(&buf)?;
assert_eq!(message.body().unwrap().body(),
           b"Hello world!");

Or, in strict mode:

use std::io::{self, Result, Read};
use sequoia_openpgp as openpgp;
use openpgp::armor::{Reader, ReaderMode, Kind};

let data =
    "-----BEGIN PGP ARMORED FILE-----

     SGVsbG8gd29ybGQh
     =s4Gu
     -----END PGP ARMORED FILE-----";

let mut cursor = io::Cursor::new(&data);
let mut reader = Reader::new(&mut cursor, ReaderMode::Tolerant(Some(Kind::File)));

let mut content = String::new();
reader.read_to_string(&mut content)?;
assert_eq!(content, "Hello world!");
assert_eq!(reader.kind(), Some(Kind::File));

pub fn from_reader<R, M>(reader: R, mode: M) -> Self where
    R: 'a + Read,
    M: Into<Option<ReaderMode>>, 
[src]

Creates a Reader from an io::Reader.

pub fn from_file<P, M>(path: P, mode: M) -> Result<Self> where
    P: AsRef<Path>,
    M: Into<Option<ReaderMode>>, 
[src]

Creates a Reader from a file.

pub fn from_bytes<M>(bytes: &'a [u8], mode: M) -> Self where
    M: Into<Option<ReaderMode>>, 
[src]

Creates a Reader from a buffer.

pub fn kind(&self) -> Option<Kind>[src]

Returns the kind of data this reader is for.

Useful if the kind of data is not known in advance. If the header has not been encountered yet (try reading some data first!), this function returns None.

pub fn headers(&mut self) -> Result<&[(String, String)]>[src]

Returns the armored headers.

The tuples contain a key and a value.

Note: if a key occurs multiple times, then there are multiple entries in the vector with the same key; values with the same key are not combined.

Examples

use std::io::{self, Read};
use sequoia_openpgp as openpgp;
use openpgp::armor::{Reader, ReaderMode, Kind};

let data =
    "-----BEGIN PGP ARMORED FILE-----
     First: value
     Header: value

     SGVsbG8gd29ybGQh
     =s4Gu
     -----END PGP ARMORED FILE-----";

let mut cursor = io::Cursor::new(&data);
let mut reader = Reader::new(&mut cursor, ReaderMode::Tolerant(Some(Kind::File)));

let mut content = String::new();
reader.read_to_string(&mut content)?;
assert_eq!(reader.headers().unwrap(),
   &[("First".into(), "value".into()),
     ("Header".into(), "value".into())]);

Trait Implementations

impl<'a> BufferedReader<Cookie> for Reader<'a>[src]

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

impl<'a> Display for Reader<'a>[src]

impl<'a> Read for Reader<'a>[src]

Auto Trait Implementations

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

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

impl<'a> !Sync for Reader<'a>

impl<'a> Unpin for Reader<'a>

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.