9 releases

0.1.11 Feb 19, 2024
0.1.10 Feb 14, 2024
0.1.8 Jan 21, 2024
0.1.6 Dec 30, 2023
0.1.3 Nov 29, 2023

#364 in Testing

Download history

252 downloads per month
Used in 2 crates

MIT/Apache

26KB
395 lines

TLV Parser

Crates.io Crates.io build workflow release workflow

This is a TLV (Tag-Length-Value) parser implemented in Rust and PHP. The parser can decode TLV-encoded data and represents each tag as a struct called Tag. The Tag struct has the following fields:

  • id: Vector of bytes representing the tag identifier.
  • length: Length of the value field.
  • value: Vector of bytes representing the value.

Additionally, the Tag struct has a method is_constructed to check if the tag is constructed.

Run it as a PHP Web Server With Precompiled Rust Program

  1. Download the source code and go to the root directory of your source code
  2. Run below command inside PowerShell:
     .\tlv_parser_downloader.bat
    
  3. Run PHP Web Server using below command:
    php -S localhost:12345
    
  4. Open your browser and go to the link below:
    localhost:12345
    

Important Note: As the PHP Web server uses a rust program to parse the message, you will need it. You can achieve this program by building release of the rust written program from the source or you can downlaod the executable file with tlv_parser_downloader as it mentioned above.

How to use as library

    use emv_tlv_parser::parse_tlv;
    let data_raw = "6F1A840E315041592E5359532E4444463031A5088801025F2D02656E";

    match parse_tlv(data_raw.to_string()) { 
        Ok(tags) => tags.iter().for_each(|tag| println!("{}", tag)), 
        Err(e) => eprintln!("Error parsing TLV: {}", e) 
    }

Run The Sample And Tests

To run the program, use the following command: cargo run

To run the tests, use the following command: cargo test

Dependencies

~1.2–1.7MB
~33K SLoC