[−][src]Struct sequoia_openpgp::armor::Reader
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]
R: 'a + Read,
M: Into<Option<ReaderMode>>,
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]
R: 'a + Read,
M: Into<Option<ReaderMode>>,
Creates a Reader
from an io::Read
er.
pub fn from_file<P, M>(path: P, mode: M) -> Result<Self> where
P: AsRef<Path>,
M: Into<Option<ReaderMode>>,
[src]
P: AsRef<Path>,
M: Into<Option<ReaderMode>>,
Creates a Reader
from a file.
pub fn from_bytes<M>(bytes: &'a [u8], mode: M) -> Self where
M: Into<Option<ReaderMode>>,
[src]
M: Into<Option<ReaderMode>>,
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(&mut self, buf: &mut [u8]) -> Result<usize>
[src]
fn read_vectored(&mut self, bufs: &mut [IoSliceMut]) -> Result<usize, Error>
1.36.0[src]
fn is_read_vectored(&self) -> bool
[src]
unsafe fn initializer(&self) -> Initializer
[src]
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn bytes(self) -> Bytes<Self>
1.0.0[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
fn take(self, limit: u64) -> Take<Self>
1.0.0[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,