Skip to main content

Crate facet_asn1

Crate facet_asn1 

Source
Expand description

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::Facet;
use facet_asn1::to_vec;

#[derive(Facet)]
struct Point { x: i32, y: i32 }

let point = Point { x: 10, y: 20 };
let bytes = to_vec(&point).unwrap();

§Deserialization

use facet::Facet;
use facet_asn1::from_slice;

#[derive(Facet)]
struct Point { x: i32, y: i32 }

// DER encoding of Point { x: 10, y: 20 }
let bytes = &[0x30, 0x06, 0x02, 0x01, 0x0A, 0x02, 0x01, 0x14];
let point: Point = from_slice(bytes).unwrap();

§Type Mapping

Rust TypeASN.1 Type
boolBOOLEAN
i8, i16, i32, i64INTEGER
u8, u16, u32, u64INTEGER
f32, f64REAL
String, &strUTF8String
Vec<u8>, &[u8]OCTET STRING
structSEQUENCE
Vec<T>SEQUENCE OF
Option<T>Optional field
()NULL

Structs§

Asn1Error
ASN.1 parsing error.
Asn1Parser
ASN.1 DER parser.
Asn1SerializeError
ASN.1 serialization error.
Asn1Serializer
ASN.1 DER serializer.

Enums§

Asn1ErrorKind
The kind of ASN.1 error.
DeserializeError
Error produced by the format deserializer.

Functions§

from_slice
Deserialize a value from ASN.1 DER bytes into an owned type.
from_slice_borrowed
Deserialize a value from ASN.1 DER bytes, allowing zero-copy borrowing.
to_vec
Serialize a value to ASN.1 DER bytes.