#tlv

nightly no-std tlv_parser

BER-TLV parsing & emitting library

13 unstable releases (4 breaking)

0.4.0 Apr 10, 2018
0.3.0 Mar 8, 2018
0.2.0 Nov 21, 2017
0.1.6 May 3, 2017
0.1.1 Jul 30, 2016

#63 in Parser implementations

Download history 6/week @ 2018-08-17 38/week @ 2018-08-24 31/week @ 2018-08-31 23/week @ 2018-09-07 17/week @ 2018-09-14 21/week @ 2018-09-21 62/week @ 2018-09-28 41/week @ 2018-10-05 15/week @ 2018-10-12 140/week @ 2018-10-19 22/week @ 2018-10-26 56/week @ 2018-11-02 55/week @ 2018-11-09

53 downloads per month

MIT/Apache

19KB
404 lines

tlv-parser

Build Status Latest Version Docs

Library for parsing BER-TLV

Documentation

Library is early development stage and supports parsing from &[u8] and emitting Vec<u8>.

For now, it only builds on nightly.

Crate is no_std compatible if you can use core::collections.

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
~23K SLoC