Function rocket::mtls::x509::ber::parse_ber_optional

source ·
pub fn parse_ber_optional<'a, F>(f: F) -> impl FnMut(&'a [u8])
where F: FnMut(&'a [u8]) -> Result<(&'a [u8], BerObject<'a>), Err<Error>>,
Available on crate feature mtls only.
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.


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);