Expand description
This crate helps you to DER-(de-)serialize various types. It provides some traits to convert
between encoded data, DER-objects and native types as well and implements them for some common
types. If you build it with the derive
-feature (enabled by default), you can use
#[derive(Asn1Der)]
to derive the traits for your named structs.
The following types have built-in support:
DerObject
: A generic DER-object-wrapper that can hold any object (DerObject{ tag: u8, payload: Vec<u8> }
)()
: The ASN.1-NULL-typebool
: The ASN.1-BOOLEAN-typeVec<u8>
: The ASN.1-OctetString-typeString
: The ASN.1-UTF8String-typeu128
: The ASN.1-INTEGER-type (within[0, 2^128)
)Vec<T>
: The ASN.1-SEQUENCE-type for any typeT
that implementsFromDerObject
andIntoDerObject
With the derive
-feature you can automatically derive FromDerObject
and IntoDerObject
:
#[macro_use] extern crate asn1_der;
use ::asn1_der::{ FromDerObject, IntoDerObject };
#[derive(Asn1Der, Default)] // Now our struct supports all DER-conversion-traits
struct Address {
street: String,
house_number: u128,
postal_code: u128,
state: String,
country: String
}
#[derive(Asn1Der, Default)]
struct Customer {
name: String,
e_mail_address: String,
postal_address: Address
}
let my_customer = Customer::default();
// Serialization:
let mut serialized = vec![0u8; my_customer.serialized_len()];
my_customer.serialize(serialized.iter_mut()).unwrap();
// Deserialization (this returns our customer if the data is valid):
let my_customer = Customer::deserialize(serialized.iter()).unwrap();
Structs
A wrapper around a DER length
A generic DER object
A wrapper around a DER value
Enums
An asn1_der
-related error
A wrapper around a DER tag that is DER-(de-)serializable
Traits
A trait for converting a DER object into a native element
A trait for converting native elements into a DER object
An extension that allows you to safely convert a u128
to a smaller type