20 releases

Uses old Rust 2015

0.9.0 Feb 2, 2024
0.8.0 Aug 17, 2023
0.7.1 May 13, 2022
0.7.0 Aug 6, 2020
0.1.1 Jul 30, 2016

#383 in Parser implementations

Download history 599/week @ 2023-12-22 1478/week @ 2023-12-29 2490/week @ 2024-01-05 1625/week @ 2024-01-12 2165/week @ 2024-01-19 1940/week @ 2024-01-26 2758/week @ 2024-02-02 2021/week @ 2024-02-09 2663/week @ 2024-02-16 3080/week @ 2024-02-23 2436/week @ 2024-03-01 2734/week @ 2024-03-08 3277/week @ 2024-03-15 2438/week @ 2024-03-22 2276/week @ 2024-03-29 1529/week @ 2024-04-05

9,938 downloads per month

MIT/Apache

22KB
477 lines

tlv-parser

Build Status Latest Version Docs

Library for parsing BER-TLV

Library supports parsing from &[u8] and emitting Vec<u8>.

This is no_std crate if you can use core::alloc.

For usage see decode-tlv/src/main.rs.

$ echo "7003820151" | cargo run
     Running `target/debug/decode-tlv`
	 tag=70
	   tag=82,     len=1,    data=51 Q

lib.rs:

A library to parse and emit BER-TLV data.

#Examples

Parse TLV:

use tlv_parser::tlv::{Tlv, Value};

let input: Vec<u8> = vec![0x21, 0x05, 0x22, 0x03, 0x03, 0x01, 0xaa];
let tlv = Tlv::from_vec( &input ).unwrap();

if let Some(&Value::Val(ref val)) = tlv.find_val("21 / 22 / 03") {
    assert_eq!(*val, vec![0xaa]);
}

Emit constructed TLV incapsulated primitive TLV:

use tlv_parser::tlv::*;

let primitive_tlv = Tlv::new(0x01, Value::Nothing).unwrap();
let constructed_tlv = Tlv::new(0x21, Value::TlvList(vec![primitive_tlv])).unwrap();

assert_eq!(constructed_tlv.to_vec(), vec![0x21, 0x02, 0x01, 0x00]);

Dependencies

~1.5MB
~37K SLoC