metabit  

Software

TLV iterator

Rust TLV iterator

The Rust re-implementation is drawing upon experiences from previous implementations in other languages. It attempts to use Rust specifics for best usability.
The source code is available on GitHub.
The crate has been published to crates.io.

the usual pitch

Key Features
  • Zero-Copy Parsing: Iterates over binary payloads directly from a byte slice (`&[u8]`) without overhead.
  • Atomic Writer: Supports in-place mutation of TLV structures with "Ripple Effect" length propagation.
  • Multiple Formats: ASN.1 BER/DER, DGI, LV, L16, and Tag Sequences.
  • Memory Safe: Guaranteed panic-free iteration paths and rigorous bounds checking for safety-critical apps.
  • Resource Efficient: Extremely small binary footprint (~4kB) and low RAM usage.
  • Flexible Navigation: Supports tree traversal (Enter/Leave) and recursive iterators.
  • Protocol Agnostic: Decodes general TLV structures as well as specialized smartcard (ISO-7816) or cryptography (ASN1) tokens.
planned
  • No-Std Compatibility: Remove dependency on `alloc` (Vec) to allow usage in bare-metal environments and becoming fully compliant with `#![no_std]`.
  • Indefinite Length Support: Support for BER/CER indefinite length encoding. (reading)

what, why, and how

TLV are tree structures. There is a number of different TLV formats, but they all follow the pattern the abbreviation TLV outlines: Tag, Length, Value (or Type, Length, Value).

What they differ in is the representation and its constraints. The size of the size, is it fixed? How is nesting handled? Is there a single valid representation, or are variants allowed?

The metabit TLV iterator supports the TLV variants found in embedded systems, smart cards, and security: ASN.1 DER foremost, BER (reading), SIMPLE-TLV according to ISO7816, DGI, untagged LV sequences, etc. The architecture has been designed to extend it by adding further formats.

Because of its history, it has been designed for 1. security and stability, 2. small footprint, 3. speed.
No dynamic allocations except for the iterator itself at start (maximum nesting level depth * 32 bytes).
Binary code footprint: about 4 kByte.

The ASN.1 DER/BER part passes the Strozhevsky test suite.

Java TLV iterator

A bit outdated, but fully functional. see this page