[][src]Crate picky_asn1_der

Crates.io docs.rs Crates.io

picky-asn1-der

Portions of project serde_asn1_der are held by Keziah Biermann, 2019 as part of this project.

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

More advanced types are supported through wrappers:

  • Integer (as big integer)
  • Bit String
  • Object Identifier
  • Utf8 String
  • Numeric String
  • Printable String
  • IA5 String
  • Generalized Time
  • UTC Time
  • Application Tags from 0 to 15
  • Context Tags from 0 to 15

Everything sequence-like combined out of this types is also supported out of the box.

use serde::{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::{Serialize, Deserialize};

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

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

Structs

Asn1RawDer

User-provided raw DER wrapper.

Deserializer

An ASN.1-DER deserializer for serde

Serializer

An ASN.1-DER serializer for serde

Enums

Asn1DerError

A picky_asn1_der-related error

Functions

from_bytes

Deserializes T from bytes

from_reader

Deserializes T from reader

from_reader_with_max_len

Deserializes T from reader reading at most n bytes.

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