Crates.io | facet-asn1 |
lib.rs | facet-asn1 |
version | 0.28.0 |
created_at | 2025-07-24 16:24:44.507569+00 |
updated_at | 2025-07-25 12:37:29.884044+00 |
description | ASN.1 serialization and deserialization for Facet types |
homepage | |
repository | https://github.com/facet-rs/facet-asn1 |
max_upload_size | |
id | 1766268 |
size | 82,384 |
Logo by Misiasart
Thanks to all individual and corporate sponsors, without whom this work could not exist:
A #![no_std]
ASN.1 serializer and deserializer based on facet
Currently supports Distinguished Encoding Rules (DER) only
ASN.1 Type | Rust |
---|---|
BOOLEAN | bool |
INTEGER | i8 , i16 , i32 , or i64 |
OCTET STRING | Vec<u8> |
NULL | Any unit struct |
REAL | f32 or f64 |
UTF8String | String |
CHOICE | enum |
SEQUENCE | struct |
Newtype structs using the facet::Shape::type_tag
property can be used to create other basic types without any content validation:
use facet::Facet;
#[derive(Debug, Clone, Facet, PartialEq, Eq)]
#[facet(type_tag = "IA5String", transparent)]
struct IA5String(String);
You can also set context specific BER/DER tags to a given number. Implicit tags must be set as transparent.
use facet::Facet;
// ImplicitString ::= [5] IMPLICIT UTF8String
#[derive(Debug, Facet, PartialEq, Eq)]
#[facet(type_tag = "5", transparent)]
struct ImplicitString(String);
// ExplciitString ::= [5] EXPLICIT UTF8String
#[derive(Debug, Facet, PartialEq, Eq)]
#[facet(type_tag = "5")]
struct ExplicitString(String);
The tag classes UNIVERSAL
, APPLICATION
, and PRIVATE
are also supported in type_tag
s for greater flexibility.
Licensed under either of:
at your option.