[][src]Crate serde_asn1_der

License License Travis CI AppVeyor CI

serde_asn1_der

This crate implements an ASN.1-DER subset for serde.

The following types have built-in support:

  • bool: The ASN.1-BOOLEAN-type
  • u8, u16, u32, u64, u128, usize: The ASN.1-INTEGER-type
  • (): The ASN.1-NULL-type
  • &[u8], Vec<u8>: The ASN.1-OctetString-type
  • &str, String: The ASN.1-UTF8String-type
  • And everything sequence-like combined out of this types

With the serde_derive-crate you can derive Serialize and Deserialize for all non-primitive elements:

use serde_derive::{ Serialize, Deserialize };

#[derive(Serialize, Deserialize)] // Now our struct supports all DER-conversion-traits
struct Address {
	street: String,
	house_number: u128,
	postal_code: u128,
	state: String,
	country: String
}

#[derive(Serialize, Deserialize)] // Now our struct supports all DER-conversion-traits too
struct Customer {
	name: String,
	e_mail_address: String,
	postal_address: Address
}

Example

use serde_asn1_der::{ to_vec, from_bytes };
use serde_derive::{ Serialize, Deserialize };

#[derive(Serialize, Deserialize)]
struct TestStruct {
	number: u8,
	#[serde(with = "serde_bytes")]
	vec: Vec<u8>,
	tuple: (usize, ())
}

fn main() {
	let plain = TestStruct{ number: 7, vec: b"Testolope".to_vec(), tuple: (4, ()) };
	let serialized = to_vec(&plain).unwrap();
	let deserialized: TestStruct = from_bytes(&serialized).unwrap();
}

Re-exports

pub use serde;

Structs

Deserializer

An ASN.1-DER deserializer for serde

Serializer

An ASN.1-DER serializer for serde

Enums

SerdeAsn1DerError

A serde_asn1_der-related error

Functions

from_bytes

Deserializes T from bytes

from_reader

Deserializes T from reader

to_byte_buf

Serializes value to buf and returns the amount of serialized bytes

to_bytes

Serializes value to buf and returns the amount of serialized bytes

to_vec

Serializes value

to_writer

Serializes value to writer and returns the amount of serialized bytes

Type Definitions

Result

Syntactic sugar for Result<T, SerdeAsn1DerError>