Derive Macro asn1_rs::DerSequence

source · []
#[derive(DerSequence)]
{
    // Attributes available to this derive:
    #[debug_derive]
    #[default]
    #[optional]
    #[tag_explicit]
    #[tag_implicit]
    #[error]
    #[map_err]
}
Expand description

DerSequence custom derive

DerSequence is a custom derive attribute, to derive both BER and DER Sequence parsers automatically from the structure definition. This attribute will automatically derive implementations for the following traits:

DerSequence implies BerSequence, and will conflict with this custom derive.

Parsers will be automatically derived from struct fields. Every field type must implement the FromDer trait.

See derive documentation for more examples and documentation.

Examples

To parse the following ASN.1 structure:

S ::= SEQUENCE {
    a INTEGER(0..2^32),
    b INTEGER(0..2^16),
    c INTEGER(0..2^16),
}

Define a structure and add the DerSequence derive:

use asn1_rs::*;

#[derive(DerSequence)]
struct S {
  a: u32,
  b: u16,
  c: u16
}

Debugging

To help debugging the generated code, the #[debug_derive] attribute has been added.

When this attribute is specified, the generated code will be printed to stderr during compilation.

Example:

use asn1_rs::*;

#[derive(DerSequence)]
#[debug_derive]
struct S {
  a: u32,
}