[][src]Crate asn1_der

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:

#[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

DerLength

A wrapper around a DER length

DerObject

A generic DER object

DerValue

A wrapper around a DER value

Enums

Asn1DerError

An asn1_der-related error

DerTag

A wrapper around a DER tag that is DER-(de-)serializable

Traits

FromDerObject

A trait for converting a DER object into a native element

IntoDerObject

A trait for converting native elements into a DER object

U128Ext

An extension that allows you to safely convert a u128 to a smaller type