Expand description
§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-typeu8,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.
Re-exports§
Structs§
- VecBacking
- A newtype wrapper around a
&'a mut Vec<u8>that implementsSinkandInto<&'a [u8]>
Enums§
- Serde
Asn1 DerError - A
serde_asn1_dererror
Functions§
- from_
bytes - Deserializes
Tfrombytes - from_
reader - Copies the first top-level object from
readerintobackingand deserializes it from there - from_
source - Copies the first top-level object from
sourceintobackingand deserializes it from there - to_sink
- Serializes
valuetobufand returns the amount of serialized bytes - to_vec
- Serializes
value - to_
writer - Serializes
valuetowriterand returns the amount of serialized bytes
Type Aliases§
- Result
- Syntactic sugar for
Result<T, Asn1DerError>