https://github.com/entur/tlv-pull-parser
TLV pull-parser for the JVM
https://github.com/entur/tlv-pull-parser
emv java mastercard mts7 tlv visa
Last synced: 8 months ago
JSON representation
TLV pull-parser for the JVM
- Host: GitHub
- URL: https://github.com/entur/tlv-pull-parser
- Owner: entur
- License: eupl-1.2
- Created: 2025-02-26T22:14:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-11T11:25:24.000Z (9 months ago)
- Last Synced: 2025-09-11T13:30:39.814Z (9 months ago)
- Topics: emv, java, mastercard, mts7, tlv, visa
- Language: Java
- Homepage:
- Size: 99.6 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# tlv-pull-parser
This project hosts a TLV parser and a few utilities for working with TLV content from smart cards.
* Efficient TLV pull-parser
* reusable instances
* minimal/zero object creation
* simple drill-down support
* code structure mirrors TLV data structure
* Customizable TLV pretty-printer
The project has zero dependencies.
# License
[European Union Public Licence v1.2](https://eupl.eu/).
# Usage
Get your APDU response, then create a parser:
```java
byte[] responseApdu = ...
LenientTlvPullParser pullParser = new LenientTlvPullParser(responseApdu, 0, responseApdu.length - 2);
```
and note that parser instances are reusable.
Iterate over tags
```java
do {
int tag = pullParser.nextTag();
if(tag == -1) {
break;
}
// your code here
} while(true);
```
The parser does not automatically go into child containers (i.e. like a JSON pull parser would), drill down must be done manually.
For targeting a structure like
```
6F 56 -- Template, File Control Parameters and File Management Data (FCI)
84 07 -- Dedicated File (DF) Name
A0 00 00 00 04 10 10
A5 4B -- File Control Information (FCI) Proprietary Template
50 10 -- Application Label
Debit Mastercard
```
drill down the built-in payload parser chaining:
```java
LenientTlvPullParser rootTemplate = pullParser.parseTagLengthValuePayload(0x6F); // skip to tag + drill down
if(rootTemplate != null) {
LenientTlvPullParser proprietaryTemplate = rootTemplate.parseTagLengthValuePayload(0xA5); // skip to tag + drill down
if(proprietaryTemplate != null) {
// process application label and so on
}
}
```
where each call to `parseTagLengthValuePayload` returns a child `LenientTlvPullParser` which works on the same buffer,
but with different offsets. Consuming all child parser contents before accessing the parent parser again is not necessary.
# Release
Release version is determined from the latest release tag. Add `[major|minor|patch]` to the commit message to control version increment.