Custom derive support for the
This crate requires Rust 1.65 at a minimum.
We may change the MSRV in the future, but it will be accompanied by a minor version bump.
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Custom derive support for the
This crate contains custom derive macros intended to be used in the following way:
Choice: map ASN.1
CHOICEto a Rust enum.
Enumerated: map ASN.1
ENUMERATEDto a C-like Rust enum.
Sequence: map ASN.1
SEQUENCEto a Rust struct.
ValueOrd: determine DER ordering for ASN.1
Note that this crate shouldn’t be used directly, but instead accessed
by using the
derive feature of the
der crate, which re-exports the
above macros from the toplevel.
der crate is designed to be easily usable in embedded environments,
including ones where code size comes at a premium.
This crate (i.e.
der_derive) is able to generate code which is
significantly smaller than
serde_derive. This is because the
crate has been designed with high-level abstractions which reduce
code size, including trait object-based encoders which allow encoding
logic which is duplicated in
serde serializers to be implemented in
a single place in the
This is a deliberate tradeoff in terms of performance, flexibility, and
code size. At least for now, the
der crate is optimizing for leveraging
as many abstractions as it can to minimize code size.
This attribute can be used to declare the tagging mode used by a particular ASN.1 module.
It’s used when parsing
The default is
EXPLICIT, so the attribute only needs to be added when
a particular module is declared
The following attributes can be added to either the fields of a particular
struct or the variants of a particular
This attribute can be added to associate a particular
tag number with a given enum variant or struct field.
The value must be quoted and contain a number, e.g.
#[asn1(context_specific = "29")].
This behaves like
default attribute, allowing you to
specify the path to a function which returns a default value.
This attribute can be applied to the fields of
struct types, and will
skip over unrecognized lower-numbered
CONTEXT-SPECIFIC fields when
looking for a particular field of a struct.
This attribute explicitly annotates a field as
This attribute can be used to specify the ASN.1 type for a particular
enum variant or
It’s presently mandatory for all
enum variants, even when using one of
the ASN.1 types defined by this crate.
For structs, placing this attribute on a field makes it possible to
decode/encode types which don’t directly implement the
traits but do impl
From for one of the ASN.1 types
listed below (use the ASN.1 type keywords as the
BIT STRING: performs an intermediate conversion to
IA5String: performs an intermediate conversion to
GeneralizedTime: performs an intermediate conversion to
OCTET STRING: performs an intermediate conversion to
PrintableString: performs an intermediate conversion to
UTCTime: performs an intermediate conversion to
UTF8String: performs an intermediate conversion to
This attribute can be used to specify that an “inner” type is constructed. It is most
commonly used when a
CHOICE has a constructed inner type.
Note: please open a GitHub Issue if you would like to request support for additional ASN.1 types.