pub fn parse_x509_pem(i: &[u8]) -> IResult<&[u8], Pem, PEMError>
Expand description

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

Return a structure describing the PEM object: the enclosing tag, and the data. Allocates a new buffer for the decoded data.

Note that only the first PEM block is decoded. To iterate all blocks from PEM data, use Pem::iter_from_buffer.

For X.509 (CERTIFICATE tag), the data is a certificate, encoded in DER. To parse the certificate content, use Pem::parse_x509 or parse_x509_certificate.

Examples found in repository?
examples/print-crl.rs (line 146)
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
pub fn main() -> io::Result<()> {
    for file_name in env::args().skip(1) {
        // placeholder to store decoded PEM data, if needed
        let tmpdata;

        println!("File: {}", file_name);
        let data = std::fs::read(file_name.clone()).expect("Unable to read file");
        let der_data: &[u8] = if (data[0], data[1]) == (0x30, 0x82) {
            // probably DER
            &data
        } else {
            // try as PEM
            let (_, data) = parse_x509_pem(&data).expect("Could not decode the PEM file");
            tmpdata = data;
            &tmpdata.contents
        };
        let (_, crl) = parse_x509_crl(der_data).expect("Could not decode DER data");
        print_crl_info(&crl);
    }
    Ok(())
}