Function rocket::mtls::x509::der_parser::ber::parse_ber_sequence_defined

source ·
pub fn parse_ber_sequence_defined<'a, F>(f: F) -> impl FnMut(&'a [u8])
where F: FnMut(&'a [u8]) -> Result<(&'a [u8], Vec<BerObject<'a>>), Err<Error>>,
Available on crate feature mtls only.
Expand description

Parse a defined sequence of DER elements (function version)

Given a list of expected parsers, apply them to build a DER sequence and return the remaining bytes and the built object.

The remaining bytes point after the sequence: any bytes that are part of the sequence but not parsed are ignored.

The object header is not available to the parsing function, and the returned type is always a BerObject. For a generic version, see parse_ber_sequence_defined_g.


Parsing a sequence of identical types (same as parse_ber_sequence_of):

use nom::combinator::complete;
use nom::multi::many1;

fn localparse_seq(i:&[u8]) -> BerResult {

let (rem, v) = localparse_seq(&bytes).expect("parsing failed");

Parsing a defined sequence with different types:

use nom::combinator::map;
use nom::sequence::tuple;

/// Read a DER-encoded object:
///     a INTEGER,
/// }
fn localparse_seq(i:&[u8]) -> BerResult {
        // the nom `tuple` combinator returns a tuple, so we have to map it
        // to a list
            tuple((parse_ber_integer, parse_ber_octetstring)),
            |(a, b)| vec![a, b]

let (rem, v) = localparse_seq(&bytes).expect("parsing failed");