Struct sequoia_openpgp::armor::Reader [−][src]
pub struct Reader<'a> { /* fields omitted */ }
Expand description
A filter that strips ASCII Armor from a stream of data.
Implementations
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 + Send + Sync,
M: Into<Option<ReaderMode>>,
[src]
pub fn from_reader<R, M>(reader: R, mode: M) -> Self where
R: 'a + Read + Send + Sync,
M: Into<Option<ReaderMode>>,
[src]Creates a Reader
from an io::Read
er.
Creates a Reader
from a file.
Creates a Reader
from a buffer.
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.
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()?, &[("First".into(), "value".into()), ("Header".into(), "value".into())]);
Trait Implementations
Returns a reference to the internal buffer. Read more
Ensures that the internal buffer has at least amount
bytes
of data, and returns it. Read more
Like data()
, but returns an error if there is not at least
amount
bytes available. Read more
Consumes some of the data. Read more
A convenience function that combines data()
and consume()
. Read more
A convenience function that effectively combines data_hard()
and consume()
. Read more
Returns a mutable reference to the inner BufferedReader
, if
any. Read more
Returns a reference to the inner BufferedReader
, if any.
fn into_inner<'b>(
self: Box<Self>
) -> Option<Box<dyn BufferedReader<Cookie> + 'b>> where
Self: 'b,
[src]
fn into_inner<'b>(
self: Box<Self>
) -> Option<Box<dyn BufferedReader<Cookie> + 'b>> where
Self: 'b,
[src]Returns the underlying reader, if any. Read more
Sets the BufferedReader
’s cookie and returns the old value.
Returns a reference to the BufferedReader
’s cookie.
Returns a mutable reference to the BufferedReader
’s cookie.
Returns all of the data until EOF. Like data()
, this does not
actually consume the data that is read. Read more
Checks whether this reader is consummated. Read more
A convenience function for reading a 16-bit unsigned integer in big endian format. Read more
A convenience function for reading a 32-bit unsigned integer in big endian format. Read more
Reads until either terminal
is encountered or EOF. Read more
Discards the input until one of the bytes in terminals is encountered. Read more
Discards the input until one of the bytes in terminals
is
encountered. Read more
Like data_consume_hard()
, but returns the data in a
caller-owned buffer. Read more
Like steal()
, but instead of stealing a fixed number of
bytes, steals all of the data until the end of file. Read more
Like steal_eof()
, but instead of returning the data, the
data is discarded. Read more
A helpful debugging aid to pretty print a Buffered Reader stack. Read more
fn as_boxed<'a>(self) -> Box<dyn BufferedReader<C> + 'a, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
where
Self: 'a,
[src]
fn as_boxed<'a>(self) -> Box<dyn BufferedReader<C> + 'a, Global>ⓘNotable traits for Box<R, Global>
impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
A: Allocator + 'static,
F: Future + Unpin + ?Sized, type Output = <F as Future>::Output;
where
Self: 'a,
[src]Boxes the reader.
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Like read
, except that it reads into a slice of buffers. Read more
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
read_initializer
)Determines if this Read
er can work with buffers of uninitialized
memory. Read more
Read all bytes until EOF in this source, placing them into buf
. Read more
Read all bytes until EOF in this source, appending them to buf
. Read more
Read the exact number of bytes required to fill buf
. Read more
Creates a “by reference” adaptor for this instance of Read
. Read more
Creates an adaptor which will chain this stream with another. Read more
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Reader<'a>
impl<'a> !UnwindSafe for Reader<'a>