rusticata / x509-parser

X.509 parser written in pure Rust. Fast, zero-copy, safe.
Other
206 stars 67 forks source link

PEM parser only returns first word of label #135

Closed mgoldenberg closed 1 year ago

mgoldenberg commented 1 year ago

To give a minimal example, the following code emits the proceeding output.

Code

use x509_parser;

const PEM_BYTES: &[u8] = 
    b"-----BEGIN MULTI WORD LABEL-----\n-----END MULTI WORD LABEL-----";

fn main() {
    let (_, pem) = x509_parser::pem::parse_x509_pem(PEM_BYTES).expect("should parse pem");
    assert_eq!(pem.label, "MULTI WORD LABEL");
}

Output

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"MULTI"`,
 right: `"MULTI WORD LABEL"`', src/main.rs:8:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Is this expected behavior? I'm certain that many implementations of PEM parsers allow for labels composed of multiple words (see openssl). And I'm pretty sure that the PEM encoding standard agrees with this - the RFC isn't explicit about it, so perhaps there's room for interpretation (see RFC7468).