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.
European Union Public Licence v1.2.
Get your APDU response, then create a parser:
byte[] responseApdu = ...
LenientTlvPullParser pullParser = new LenientTlvPullParser(responseApdu, 0, responseApdu.length - 2);and note that parser instances are reusable.
Iterate over tags
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:
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 version is determined from the latest release tag. Add [major|minor|patch] to the commit message to control version increment.