Function der_parser::der::parse_der_set_defined [−][src]
pub fn parse_der_set_defined<'a, F>(
f: F
) -> impl FnMut(&'a [u8]) -> BerResult<'_> where
F: FnMut(&'a [u8]) -> BerResult<'_, Vec<DerObject<'_>>>,
Expand description
Parse a defined set of DER elements (function version)
Given a list of expected parsers, apply them to build a DER set and return the remaining bytes and the built object.
The remaining bytes point after the set: any bytes that are part of the sequence but not
parsed are ignored.
The nom combinator all_consuming
can be used to ensure all the content is parsed.
The object header is not available to the parsing function, and the returned type is always a
DerObject
.
For a generic version, see parse_der_set_defined_g
.
Examples
Parsing a set of identical types (same as parse_der_set_of
):
use nom::combinator::complete; use nom::multi::many1; fn localparse_seq(i:&[u8]) -> BerResult { parse_der_set_defined( many1(complete(parse_der_integer)) )(i) } let (rem, v) = localparse_seq(&bytes).expect("parsing failed");
Parsing a defined set with different types:
use nom::combinator::map; use nom::sequence::tuple; /// Read a DER-encoded object: /// SET { /// a INTEGER, /// b OCTETSTRING /// } fn localparse_set(i:&[u8]) -> BerResult { parse_der_set_defined( // the nom `tuple` combinator returns a tuple, so we have to map it // to a list map( tuple((parse_der_integer, parse_der_octetstring)), |(a, b)| vec![a, b] ) )(i) } let (rem, v) = localparse_set(&bytes).expect("parsing failed");