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)*) => { ... };
}

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 DerObjectHeader 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:

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

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