[−][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 + Send + Sync,
M: Into<Option<ReaderMode>>,
[src]
R: 'a + Read + Send + Sync,
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.
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]
R: 'a + Read + Send + Sync,
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.
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
impl<'a> BufferedReader<Cookie> for Reader<'a>
[src]
pub fn buffer(&self) -> &[u8]
[src]
pub fn data(&mut self, amount: usize) -> Result<&[u8]>
[src]
pub fn consume(&mut self, amount: usize) -> &[u8]
[src]
pub fn data_consume(&mut self, amount: usize) -> Result<&[u8]>
[src]
pub fn data_consume_hard(&mut self, amount: usize) -> Result<&[u8]>
[src]
pub fn consummated(&mut self) -> bool
[src]
pub fn get_mut(&mut self) -> Option<&mut dyn BufferedReader<Cookie>>
[src]
pub fn get_ref(&self) -> Option<&dyn BufferedReader<Cookie>>
[src]
pub fn into_inner<'b>(
self: Box<Self>
) -> Option<Box<dyn BufferedReader<Cookie> + 'b>> where
Self: 'b,
[src]
self: Box<Self>
) -> Option<Box<dyn BufferedReader<Cookie> + 'b>> where
Self: 'b,
pub fn cookie_set(&mut self, cookie: Cookie) -> Cookie
[src]
pub fn cookie_ref(&self) -> &Cookie
[src]
pub fn cookie_mut(&mut self) -> &mut Cookie
[src]
pub fn data_hard(&mut self, amount: usize) -> Result<&[u8], Error>
[src]
pub fn data_eof(&mut self) -> Result<&[u8], Error>
[src]
pub fn eof(&mut self) -> bool
[src]
pub fn read_be_u16(&mut self) -> Result<u16, Error>
[src]
pub fn read_be_u32(&mut self) -> Result<u32, Error>
[src]
pub fn read_to(&mut self, terminal: u8) -> Result<&[u8], Error>
[src]
pub fn drop_until(&mut self, terminals: &[u8]) -> Result<usize, Error>
[src]
pub fn drop_through(
&mut self,
terminals: &[u8],
match_eof: bool
) -> Result<(Option<u8>, usize), Error>
[src]
&mut self,
terminals: &[u8],
match_eof: bool
) -> Result<(Option<u8>, usize), Error>
pub fn steal(&mut self, amount: usize) -> Result<Vec<u8, Global>, Error>
[src]
pub fn steal_eof(&mut self) -> Result<Vec<u8, Global>, Error>
[src]
pub fn drop_eof(&mut self) -> Result<bool, Error>
[src]
pub fn dump(&self, sink: &mut dyn Write) -> Result<(), Error>
[src]
pub fn as_boxed<'a>(self) -> Box<dyn BufferedReader<C> + 'a, Global> where
Self: 'a,
[src]
Self: 'a,
impl<'a> Debug for Reader<'a>
[src]
impl<'a> Display for Reader<'a>
[src]
impl<'a> Read for Reader<'a>
[src]
pub fn read(&mut self, buf: &mut [u8]) -> Result<usize>
[src]
pub fn read_vectored(
&mut self,
bufs: &mut [IoSliceMut<'_>]
) -> Result<usize, Error>
1.36.0[src]
&mut self,
bufs: &mut [IoSliceMut<'_>]
) -> Result<usize, Error>
pub fn is_read_vectored(&self) -> bool
[src]
pub unsafe fn initializer(&self) -> Initializer
[src]
pub fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
1.0.0[src]
pub fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
pub fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
pub fn by_ref(&mut self) -> &mut Self
1.0.0[src]
pub fn bytes(self) -> Bytes<Self>
1.0.0[src]
pub fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
pub fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Reader<'a>
[src]
impl<'a> Send for Reader<'a>
[src]
impl<'a> Sync for Reader<'a>
[src]
impl<'a> Unpin for Reader<'a>
[src]
impl<'a> !UnwindSafe for Reader<'a>
[src]
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,
pub 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> Same<T> for T
type Output = T
Should always be Self
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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.
pub 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>,