Macro eagre_asn1::der_sequence
[−]
[src]
macro_rules! der_sequence { ($struct_name:ident : $($field_name:ident : $tagtype:ident $(TAG $tagclass:ident $tagval:expr ;)* TYPE $field_type:ty),+) => { ... }; ($struct_name:ident : $($field_name:ident : $tagtype:ident $(TAG $tagclass:ident $tagval:expr ;)* TYPE $field_type:ty),+,) => { ... }; }
Macro to create sequence implementation for a struct
The macro is basically repeating the structure of the struct, but it includes additional information about what tag should be used.
EXPLICIT TAG <CLASS> <TAG>;
is used for explicit taggingIMPLICIT TAG <CLASS> <TAG>;
is used for implicit taggingNOTAG
is used if no tagging is required
<CLASS>
is replaced by one of
UNIVERSAL
for 00APPLICATION
for 01CONTEXT
for 10PRIVATE
for 11
Example
struct SomeStruct { pub foo: String, pub bar: i32, } der_sequence! { SomeStruct: foo: EXPLICIT TAG APPLICATION 42; TYPE String, bar: NOTAG TYPE i32, } let data = SomeStruct { foo: "I am a random String".to_string(), bar: 42, }; let encoded = data.der_bytes().unwrap(); // Send to far away planet let decoded = SomeStruct::der_from_bytes(encoded).unwrap(); assert_eq!(data, decoded);
Implementation Details
Because I am not the best with macro_rules!
the only way I got this macro working is using
ident
s which are converted to strings and matched against other strings. Improvements are
welcome :)