facet-asn1
ASN.1 DER/BER serialization and deserialization for facet.
This crate provides ASN.1 DER (Distinguished Encoding Rules) support via the
FormatParser and FormatSerializer traits.
ASN.1 Overview
ASN.1 (Abstract Syntax Notation One) is a standard interface description language for defining data structures that can be serialized and deserialized in a cross-platform way. DER is a specific encoding rule that ensures canonical encoding.
Serialization
use Facet;
use to_vec;
let point = Point ;
let bytes = to_vec.unwrap;
Deserialization
use Facet;
use from_slice;
// DER encoding of Point { x: 10, y: 20 }
let bytes = &;
let point: Point = from_slice.unwrap;
Type Mapping
| Rust Type | ASN.1 Type |
|---|---|
bool |
BOOLEAN |
i8, i16, i32, i64 |
INTEGER |
u8, u16, u32, u64 |
INTEGER |
f32, f64 |
REAL |
String, &str |
UTF8String |
Vec<u8>, &[u8] |
OCTET STRING |
| struct | SEQUENCE |
Vec<T> |
SEQUENCE OF |
Option<T> |
Optional field |
() |
NULL |