#asn1-der #asn-1 #serde #no-panic

serde_asn1_der

A basic ASN.1-DER implementation for serde based upon asn1_der

7 releases

0.8.0 Mar 7, 2023
0.7.4 Mar 18, 2021
0.7.3 Jul 31, 2020
0.7.2 May 9, 2020
0.1.0 Mar 24, 2019

#1118 in Encoding

Download history 97/week @ 2024-07-24 163/week @ 2024-07-31 180/week @ 2024-08-07 148/week @ 2024-08-14 149/week @ 2024-08-21 195/week @ 2024-08-28 462/week @ 2024-09-04 281/week @ 2024-09-11 282/week @ 2024-09-18 188/week @ 2024-09-25 143/week @ 2024-10-02 219/week @ 2024-10-09 296/week @ 2024-10-16 339/week @ 2024-10-23 309/week @ 2024-10-30 274/week @ 2024-11-06

1,233 downloads per month
Used in rusty_vault

BSD-2-Clause OR MIT

35KB
680 lines

docs.rs License BSD-2-Clause License MIT crates.io Download numbers Travis CI AppVeyor CI dependency status

serde_asn1_der

Welcome to serde_asn1_der 🎉

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

The following types are supported:

  • bool: The ASN.1-BOOLEAN-type
  • u8, u16, u32, u64, u128, usize: The ASN.1-INTEGER-type
  • (), Option: 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();
}

AnyObject

This crate also offers a type-erased AnyObject-trait, that allows you to use Box<dyn AnyObject> instead of a specific type. To enable AnyObject, use the "any"-feature.

Dependencies

~165–430KB