Crate der_derive[−][src]
Custom derive support for the der
crate.
This crate contains custom derive macros intended to be used in the following way:
Decodable
andEncodable
: for representing ASN.1CHOICE
as a Rust enumMessage
: for representing ASN.1SEQUENCE
as a Rust struct
Note that this crate shouldn't be used directly, but instead accessed
by using the derive
feature of the der
crate.
#[asn1(type = "...")]
attribute
This attribute can be used to specify the ASN.1 type for a particular enum variant or struct field.
It's presently mandatory for all struct fields, 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 Decode
/Encode
traits but do impl From
and TryInto
and From
for one of the ASN.1 types
listed below (use the ASN.1 type keywords as the type
):
BIT STRING
: performs an intermediate conversion toder::BitString
GeneralizedTime
: performs an intermediate conversion toder::GeneralizedTime
OCTET STRING
: performs an intermediate conversion toder::OctetString
PrintableString
: performs an intermediate conversion toder::PrintableString
UTCTime
: performs an intermediate conversion toder::UtcTime
UTF8String
: performs an intermediate conversion toder::Utf8String
Example:
// NOTE: requires the `derive` feature of `der` use der::{Decodable, Encodable}; /// `Time` as defined in RFC 5280 #[derive(Decodable, Encodable)] pub enum Time { #[asn1(type = "UTCTime")] UtcTime(UtcTime), #[asn1(type = "GeneralizedTime")] GeneralTime(GeneralizedTime), }
Note: please open a GitHub Issue if you would like to request support for additional ASN.1 types.
Derive Macros
Decodable | Derive the |
Encodable | Derive the |
Message | Derive the |