Welcome to my asn1_der
-crate 🎉
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-type
- bool
: The ASN.1-BOOLEAN-type
- Vec<u8>
: The ASN.1-OctetString-type
- String
: The ASN.1-UTF8String-type
- u128
: The ASN.1-INTEGER-type (within [0, 2^128)
)
- Vec<T>
: The ASN.1-SEQUENCE-type for any type T
that implements FromDerObject
and IntoDerObject
With the derive
-feature you can automatically derive FromDerObject
and IntoDerObject
:
```rust
struct Address { street: String, housenumber: u128, postalcode: u128, state: String, country: String }
struct Customer { name: String, emailaddress: String, postal_address: Address }
// Serialization: let mut serialized = vec![0u8; mycustomer.serializedlen()]; mycustomer.serialize(serialized.itermut()).unwrap();
// Deserialization (this returns our customer if the data is valid): let my_customer = Customer::deserialize(serialized.iter()).unwrap(); ```
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:
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 panicstypes
module which defines the FromDerObject
and IntoDerObject
traits and already implements them for
some native typesThe tests are also separated into multiple files that map to the modules
asn1_der_impl!
-macro was replaced with a procedural derive macro in the asn1_der_derive
-subcrateIf 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.
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.