Struct x509_parser::pem::Pem[][src]

pub struct Pem {
    pub label: String,
    pub contents: Vec<u8>,
}

Representation of PEM data

Fields

label: String

The PEM label

contents: Vec<u8>

The PEM decoded data

Implementations

impl Pem[src]

pub fn read(r: impl BufRead + Seek) -> Result<(Pem, usize), PEMError>[src]

Read the next PEM-encoded structure, and decode the base64 data

Returns the certificate (encoded in DER) and the number of bytes read. Allocates a new buffer for the decoded data.

Note that a PEM file can contain multiple PEM blocks. This function returns the first decoded object, starting from the current reader position. To get all objects, call this function repeatedly until PEMError::MissingHeader is returned.

Examples

let file = std::fs::File::open("assets/certificate.pem").unwrap();
let subject = x509_parser::pem::Pem::read(std::io::BufReader::new(file))
     .unwrap().0
    .parse_x509().unwrap()
    .tbs_certificate.subject.to_string();
assert_eq!(subject, "CN=lists.for-our.info");

pub fn parse_x509(&self) -> Result<X509Certificate<'_>, Err<X509Error>>[src]

Decode the PEM contents into a X.509 object

pub fn iter_from_buffer(i: &[u8]) -> PemIterator<Cursor<&[u8]>>

Notable traits for PemIterator<R>

impl<R: BufRead + Seek> Iterator for PemIterator<R> type Item = Result<Pem, PEMError>;
[src]

Returns an iterator over the PEM-encapsulated parts of a buffer

Only the sections enclosed in blocks starting with -----BEGIN xxx----- and ending with -----END xxx----- will be considered. Lines before, between or after such blocks will be ignored.

The iterator is fallible: next() returns a Result<Pem, PEMError> object. An error indicates a block is present but invalid.

If the buffer does not contain any block, iterator will be empty.

pub fn iter_from_reader<R: BufRead + Seek>(reader: R) -> PemIterator<R>

Notable traits for PemIterator<R>

impl<R: BufRead + Seek> Iterator for PemIterator<R> type Item = Result<Pem, PEMError>;
[src]

Returns an iterator over the PEM-encapsulated parts of a reader

Only the sections enclosed in blocks starting with -----BEGIN xxx----- and ending with -----END xxx----- will be considered. Lines before, between or after such blocks will be ignored.

The iterator is fallible: next() returns a Result<Pem, PEMError> object. An error indicates a block is present but invalid.

If the reader does not contain any block, iterator will be empty.

Trait Implementations

impl Debug for Pem[src]

impl PartialEq<Pem> for Pem[src]

impl StructuralPartialEq for Pem[src]

Auto Trait Implementations

impl RefUnwindSafe for Pem

impl Send for Pem

impl Sync for Pem

impl Unpin for Pem

impl UnwindSafe for Pem

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> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

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

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

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> TryConv for T

impl<T> TryConv for T

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.