#tlv

nightly no-std tlv_parser

BER-TLV parsing & emitting library

16 unstable releases (6 breaking)

0.6.0 Apr 12, 2019
0.5.1 Mar 27, 2019
0.4.0 Apr 10, 2018
0.3.0 Mar 8, 2018
0.1.1 Jul 30, 2016

#63 in Parser implementations

Download history 7/week @ 2018-12-28 14/week @ 2019-01-04 33/week @ 2019-01-11 5/week @ 2019-01-18 5/week @ 2019-01-25 26/week @ 2019-02-01 11/week @ 2019-02-08 21/week @ 2019-02-15 39/week @ 2019-02-22 40/week @ 2019-03-01 25/week @ 2019-03-08 19/week @ 2019-03-15 261/week @ 2019-03-22 15/week @ 2019-03-29 39/week @ 2019-04-05

178 downloads per month

MIT/Apache

18KB
384 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. By the same reason it requries nightly compiler.

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

~1MB
~19K SLoC