#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

#74 in Parser implementations

Download history 22/week @ 2018-10-03 23/week @ 2018-10-10 134/week @ 2018-10-17 37/week @ 2018-10-24 17/week @ 2018-10-31 93/week @ 2018-11-07 21/week @ 2018-11-14 46/week @ 2018-11-21 55/week @ 2018-11-28 69/week @ 2018-12-05 25/week @ 2018-12-12 29/week @ 2018-12-19 228/week @ 2018-12-26 Download history 17/week @ 2018-09-08 21/week @ 2018-09-15 62/week @ 2018-09-22 41/week @ 2018-09-29 15/week @ 2018-10-06 140/week @ 2018-10-13 22/week @ 2018-10-20 56/week @ 2018-10-27 55/week @ 2018-11-03 47/week @ 2018-11-10 51/week @ 2018-11-17 75/week @ 2018-11-24 18/week @ 2018-12-01 42/week @ 2018-12-08

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