Function der_parser::ber::parse_ber_optional
source · pub fn parse_ber_optional<'a, F>(f: F) -> impl FnMut(&'a [u8]) -> BerResult<'a>where
F: FnMut(&'a [u8]) -> BerResult<'a>,
Expand description
Combinator for building optional BER values
To read optional BER values, it is to use the nom opt()
combinator. However, this results in
a Option<BerObject>
and prevents using some functions from this crate (the generic functions
can still be used).
This combinator is used when parsing BER values, while keeping BerObject
output only.
This function will never fail: if parsing content failed, the BER value Optional(None)
is
returned.
Example
let bytes = &[0x02, 0x03, 0x01, 0x00, 0x01];
let mut parser = parse_ber_optional(parse_ber_integer);
let (_, obj) = parser(bytes).expect("parsing failed");
assert_eq!(obj.header.tag(), Tag::Integer);
assert!(obj.as_optional().is_ok());