Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse-back not working #8

Open
robybeen opened this issue Nov 6, 2022 · 1 comment
Open

Parse-back not working #8

robybeen opened this issue Nov 6, 2022 · 1 comment

Comments

@robybeen
Copy link

robybeen commented Nov 6, 2022

Either I don't undestand how the lib should be used or there is some fishy stuff in the code. This example should serialize an empty value and parse it back, but Tlv::from_vec returns an error:

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

fn main() {
    let src = Tlv::new(0x1F, Value::Nothing).unwrap();
    let output = src.to_vec();
    let dest = Tlv::from_vec(&output).unwrap();
    assert_eq!(dest.tag(), 0x1F);
}

Output:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: TruncatedTlv', src/main.rs:6:39
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@lexxvir
Copy link
Owner

lexxvir commented Nov 7, 2022

Hi @robybeen ,

In your case there is an error in the tag number. BER-TLV rules imply that if most-significant-byte of a tag number masked by 0x1F is equal to 0x1F (tag & 0x1F == 0x1F) then tag number is consist of at least two bytes. In your case tag number is one byte size.

Now Tlv::new doesn't check the tag number provided by user. I will add such a check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants