[][src]Macro der_parser::parse_der_application

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

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 empty!() subparser as the last parsing item.

Examples

The following parses [APPLICATION 2] INTEGER:

use der_parser::ber::*;
use nom::{IResult,Err,ErrorKind};

#[derive(Debug, PartialEq)]
struct SimpleStruct {
    a: u32,
};
fn parse_app01(i:&[u8]) -> IResult<&[u8],(BerObjectHeader,SimpleStruct)> {
    parse_der_application!(
        i,
        APPLICATION 2,
        a: map_res!(parse_ber_integer,|x: BerObject| x.as_u32()) >>
           empty!() >>
        ( SimpleStruct{ a:a } )
    )
}
let bytes = &[0x62, 0x05, 0x02, 0x03, 0x01, 0x00, 0x01];
let res = parse_app01(bytes);
match res {
    Ok((rem,(hdr,app))) => {
        assert!(rem.is_empty());
        assert_eq!(hdr.tag, BerTag::Integer);
        assert!(hdr.is_application());
        assert_eq!(hdr.structured, 1);
        assert_eq!(app, SimpleStruct{ a:0x10001 });
    },
    _ => assert!(false)
}