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

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

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

Methods

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.

Example

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:

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.

Trait Implementations

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

fn read_vectored(&mut self, bufs: &mut [IoVecMut]) -> Result<usize, Error>[src]

🔬 This is a nightly-only experimental API. (iovec)

Like read, except that it reads into a slice of buffers. Read more

unsafe fn initializer(&self) -> Initializer[src]

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, placing them into buf. Read more

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
[src]

Read all bytes until EOF in this source, appending them to buf. Read more

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0
[src]

Read the exact number of bytes required to fill buf. Read more

fn by_ref(&mut self) -> &mut Self
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Read. Read more

fn bytes(self) -> Bytes<Self>
1.0.0
[src]

Transforms this Read instance to an [Iterator] over its bytes. Read more

fn chain<R>(self, next: R) -> Chain<Self, R> where
    R: Read
1.0.0
[src]

Creates an adaptor which will chain this stream with another. Read more

fn take(self, limit: u64) -> Take<Self>
1.0.0
[src]

Creates an adaptor which will read at most limit bytes from it. Read more

Auto Trait Implementations

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

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

impl<V, T> VZip for T where
    V: MultiLane<T>,