Hi,
for my smart card driver I'm currently testing Your iso7816-tlv code, referring to pub mod simple;
My task is to parse something like this (hex values): [84, 1, 2C, 97, 0, 84, 1, 24, 9E, 1, 42], which is a sequence of simple-tlv.
There is a small, known set of valid 1-byte tags: 0x8?, 0x97, 0x9E and a few more; L is 1 byte as well, <255.
Depending on the tag value, different processing is involved: First is splitting by 0x8? tags, i.e.
in the simple case shown here, 2 simple-tlv form a "group of information", stored as a struct and pushed to a Vec, thus vector's len() will be 2 here.
The point (UpdateEdit) issue with Your code is: There is no public access to the Tlv struct members tag: Tag, value: Value, thus I introduced getter methods. Perhaps You may find that useful as well, or am I mistaken (I'm quite new to Rust):
$ diff -u3 ../iso7816-tlv-master/src/simple.rs iso7816-tlv/src/simple.rs
--- ../iso7816-tlv-master/src/simple.rs 2019-09-30 13:02:57.000000000 +0200
+++ iso7816-tlv/src/simple.rs 2019-10-30 13:22:09.343488554 +0100
@@ -87,6 +87,21 @@
}
}
+ /// Returns tag number of TLV
+ pub fn tag(&self) -> u8 {
+ self.tag.0
+ }
+
+ /// Returns length of TLV
+ pub fn length(&self) -> usize {
+ self.value.0.len()
+ }
+
+ /// Returns value of TLV
+ pub fn value(&self) -> &[u8] {
+ self.value.0.as_slice()
+ }
+
/// serializes self into a byte vector.
#[allow(clippy::cast_possible_truncation)]
pub fn to_vec(&self) -> Vec<u8> {
$