asn1_der
Welcome to my asn1_der
-crate 🎉
What this crate is:
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
:
// Now our struct supports all DER-conversion-traits
// Serialization:
let mut serialized = vec!;
my_customer.serialize.unwrap;
// Deserialization (this returns our customer if the data is valid):
let my_customer = deserialize.unwrap;
Changes from 0.5.10 to 0.6.0
From 0.5.10 to 0.6.0 the library was nearly completely rewritten with a much more modular approach.
-
The library is now separated into two modules:
- The
der
module which contains the generic DER implementation which is more stringent than the previous version and uses iterators instead of slices to avoid unexpected panics - The
types
module which defines theFromDerObject
andIntoDerObject
traits and already implements them for some native types
- The
-
The tests are also separated into multiple files that map to the modules
-
The
asn1_der_impl!
-macro was replaced with a procedural derive macro in theasn1_der_derive
-subcrate
If you are looking for the old version, you can find it here – however please note that the old version is deprecated and may contain some serious issues.
Dependencies
This depends on your selected features. If you use the derive
-feature (enabled by default), the crate depends on the
quote and syn crates which are used in the procedural
macro implementation.
If you don't use the derive
-feature, this crate is dependency-less.
Long-Term Goals:
- Create a C-interface to make this library usable from C-FFI-compatible languages