structured-asn1 — borrowed ASN.1 BER/DER parsing in Rust
A Rust ASN.1 reader for BER and DER that borrows encoded values and preserves their exact byte ranges. Useful for format parsers that must verify digital signatures over the bytes received. Nested readers share depth, element, length and work limits; resource exhaustion is distinct from malformed input.
no_std + alloc by default · Rust 1.92+ · No cryptographic backend or I/O
Install
[]
= "0.1"
Enable the optional std feature for a standard-library integration, or name
alloc explicitly for an alloc-only feature graph. See the
API reference for parser limits and value types.
Quick start
use Arc;
use ;
use ;
The value is a view into bytes. Choose Parser::ber for BER input, or use
Parser::new to supply encoding and parser-local Limits explicitly. Borrowed
values require the document to remain alive.
OIDs and retained memory
OID identity uses its encoded bytes. Oid::text(&Memory) and
Arc::text(&Memory) materialize exact decimal text with fallible work and
capacity admission. Returned text retains its storage charge until released;
OID and arc values do not implement Display. Borrowed arc iteration leaves
its traversal admission to the caller.
The source version also adds OwnedOid::parse(text, &Memory) for strict
dotted-decimal identifiers with arbitrary-width arcs, and
OwnedOid::from_oid(oid, &Memory) for fallible retained copies. Its validated
immutable as_oid() view is constant-time and does not rescan the encoding.
The independent result keeps its capacity charge; these additions are not
available in the initial crates.io 0.1.0 release.
Owned vectors, maps and strings retain allocated capacity on their original
resource account. Container construction, growth and copies operate in that
declared domain. Map lookup/removal and try_iter(&Memory) may instead use a
current execution account; iteration prepays control buckets, including sparse
holes. Rebuilding a collection in another domain requires an explicit fallible
copy; retained allocations are never silently rebound.
Raw byte views and ordinary formatting/equality traits leave application-owned traversal and output storage to the caller. An explicit budget bounds admitted mechanism work; it does not automatically account arbitrary caller code.
Related crate
For X.509 certificate parsing and provider-neutral path validation, use structured-pkix. This crate reads encoding structure; it does not decide certificate trust or signature validity.
License and source
Licensed under Apache-2.0. Source, issues and contribution instructions are in signature-primitives.