Function rocket::mtls::x509::der_parser::ber::parse_ber_tagged_implicit_g

source ·
pub fn parse_ber_tagged_implicit_g<'a, T, Output, F, E>(
    tag: T,
    f: F
) -> impl FnMut(&'a [u8])
where F: Fn(&'a [u8], Header<'a>, usize) -> Result<(&'a [u8], Output), Err<E>>, E: ParseError<&'a [u8]> + From<Error>, T: Into<Tag>,
Available on crate feature mtls only.
Expand description

Read a TAGGED IMPLICIT value (generic version)

Parse a TAGGED IMPLICIT value, given the expected tag, and the content parsing function.

§Examples

The following parses [1] IMPLICIT OCTETSTRING, returning a BerObject:

fn parse_implicit_0_octetstring(i:&[u8]) -> BerResult<BerObjectContent> {
    parse_ber_tagged_implicit_g(
        2,
        parse_ber_content2(Tag::OctetString)
    )(i)
}

let res = parse_implicit_0_octetstring(bytes);

The following parses [2] IMPLICIT INTEGER into an u32, raising an error if the integer is too large:

fn parse_int_implicit(i:&[u8]) -> BerResult<u32> {
    parse_ber_tagged_implicit_g(
        2,
        |content, hdr, depth| {
            let (rem, obj_content) = parse_ber_content(Tag::Integer)(content, &hdr, depth)?;
            let value = obj_content.as_u32()?;
            Ok((rem, value))
        }
    )(i)
}

let res = parse_int_implicit(bytes);