pub fn parse_der_set_defined_g<'a, O, F, E>(f: F) -> impl FnMut(&'a [u8])
Available on crate feature
mtls
only.Expand description
Parse a defined SET object (generic version)
Given a parser for set content, apply it 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.
Unlike parse_der_set_defined
, this function allows returning any object or error type,
and also passes the object header to the callback.
ยงExamples
Parsing a defined set with different types:
pub struct MyObject<'a> {
a: u32,
b: &'a [u8],
}
/// Read a DER-encoded object:
/// SET {
/// a INTEGER (0..4294967295),
/// b OCTETSTRING
/// }
fn parse_myobject(i: &[u8]) -> BerResult<MyObject> {
parse_der_set_defined_g(
|i:&[u8], _| {
let (i, a) = parse_der_u32(i)?;
let (i, obj) = parse_der_octetstring(i)?;
let b = obj.as_slice().unwrap();
Ok((i, MyObject{ a, b }))
}
)(i)
}
let (rem, v) = parse_myobject(&bytes).expect("parsing failed");