Macro der_parser::parse_der_application[][src]

macro_rules! parse_der_application {
    ($i : expr, APPLICATION $tag : expr, $($rest : tt) *) => { ... };
    ($i : expr, $tag : expr, $($rest : tt) *) => { ... };
}
Expand description

Parse an application DER element

Read an application DER element using the provided functions. This is generally used to build a struct from a DER sequence.

The returned object is a tuple containing a BerObjectHeader and the object returned by the subparser.

To ensure the subparser consumes all bytes from the constructed object, add the eof!() subparser as the last parsing item.

Examples

The following parses [APPLICATION 2] INTEGER:

#[derive(Debug, PartialEq)]
struct SimpleStruct {
    a: u32,
}

fn parse_app01(i:&[u8]) -> BerResult<SimpleStruct> {
    parse_der_application!(
        i,
        APPLICATION 2,
        a: map_res!(parse_ber_integer,|x: BerObject| x.as_u32()) >>
           eof!() >>
        ( SimpleStruct{ a:a } )
    )
}

let bytes = &[0x62, 0x05, 0x02, 0x03, 0x01, 0x00, 0x01];
let res = parse_app01(bytes);
match res {
    Ok((rem, app)) => {
        assert!(rem.is_empty());
        assert_eq!(app, SimpleStruct{ a:0x10001 });
    },
    _ => assert!(false)
}