evsinev / ber-tlv Goto Github PK
View Code? Open in Web Editor NEWBER-TLV parser and builder
License: Apache License 2.0
BER-TLV parser and builder
License: Apache License 2.0
Hi, thanks for your great library. I've some issue with building nested BerTLV tag. The following is working as expected :
BerTlv tlv = new BerTlv(new BerTag(0x01),new byte[]{0x06});
BerTlv some = new BerTlvBuilder()
.addBytes(new BerTag(0xE3), new BerTlvBuilder().addBerTlv(tlv).buildArray())
.buildTlv();
which gives :
010106
E303010106
But when using 0 length BerTLV tag, the following is not working
BerTlv tlv = new BerTlv(new BerTag(0x01),new byte[]{});
BerTlv some = new BerTlvBuilder()
.addBytes(new BerTag(0xE3), new BerTlvBuilder().addBerTlv(tlv).buildArray())
.buildTlv();
I get :
0100
E300
But I'm expecting :
0100
E3020100
Thanks for your help
Hi
While I was using this librairy, i've encountered a bug that prevented the parsing of the following Hex String:
BF01820114DF0105A0000000049F2201EFDF020101DF030101DF0481F8A191CB87473F29349B5D60A88B3EAEE0973AA6F1A082F358D849FDDFF9C091F899EDA9792CAF09EF28F5D22404B88A2293EEBBC1949C43BEA4D60CFD879A1539544E09E0F09F60F065B2BF2A13ECC705F3D468B9D33AE77AD9D3F19CA40F23DCF5EB7C04DC8F69EBA565B1EBCB4686CD274785530FF6F6E9EE43AA43FDB02CE00DAEC15C7B8FD6A9B394BABA419D3F6DC85E16569BE8E76989688EFEA2DF22FF7D35C043338DEAA982A02B866DE5328519EBBCD6F03CDD686673847F84DB651AB86C28CF1462562C577B853564A290C8556D818531268D25CC98A4CC6A0BDFFFDA2DCCA3A94C998559E307FDDF915006D9A987B07DDAEB3BDF050103
The node "DF05" with the length of 1 and value of "03" was not found by the API (It's at the end of the String). After some debugging I've come up with a fix that I zipped and attached to this bug entry. Not being familiar with Git Hub, i've not made a push request... sorry
Have a good day!
BerTlvParser.zip
Dear Sirs,
I just trying to parse Visa CDET cards from https://play.google.com/store/apps/details?id=com.visa.app.cdet app. App's card 09 is marked as Card with '00' and 'FF' Padding.
When READ RECORD command performed:
00b2011400
Response from the card is:
700C5F340101FFFFFF9F570208409000
ber-tlv parser parses that string in the following manner:
BerTlvs{tlvs=[BerTlv{theTag=+ 70, theValue=null, theList=[BerTlv{theTag=- 5F34, theValue=[1], theList=null}, BerTlv{theTag=+ FFFFFF9F57, theValue=null, theList=[]}]}]}
But according Annex B of EMV 4.3 Book 3 value where bytes from 5 to 1 all = 1 mean "see subsequent bytes" ie all FF's should be ignored.
Could you fix this please?
Thanks in advance,
Igor
Current BerTlv find is searching for the TAG recursively and sometimes ends up returns incorrect values.
Example:
If I have the following data and want to find the BerTLV 0x80 under 0x62, it will return the 0x80 inside 0xA5.
62 19
82 02 4121
83 02 2F05
A5 03 800161
8A 01 05
8B 03 2F0605
80 02 000A
One option would be to create a findOnChildBerTlv, to limit the search to a 1 level depth.
Adding a new parameter maxDepth would be another solution.
Some tags on the card are not in standard format or have some problem, but the rest is fine. If you do not catch this exception, all information is lost when the parcel is made.
add try{} catch(){}
in BerTlvParser class at line 84
int lengthBytesCount;
int valueLength;
try {
lengthBytesCount = getLengthBytesCount(aBuf, aOffset + tagBytesCount);
valueLength = getDataLength(aBuf, aOffset + tagBytesCount);
}catch (Exception e){
lengthBytesCount = 0;
valueLength = 0;
}
One year has passed from -8. Version that would not bring in junit dependency (b3eacba) for non-test requirements and other minor improvements would be cool!
To get rid of:
[WARNING] ******************************************************************************************************************************************
[WARNING] * Required filename-based automodules detected: [ber-tlv-1.0-11.jar]. Please don't publish this project to a public artifact repository! *
[WARNING] ******************************************************************************************************************************************
BerTlvBuilder.addHex - when adding Stiring of odd length, will just process the even number of characters.
In my view either it should throw an exception/runtime exception or process all characters correctly.
The data is then skipped in HexUtil.parseHex where the size of destination buffer is integer division that doesn't work for numbers that are not power of 2.
BerTlvBuilder contains a lot of "magic numbers" (0x80
, 0x81
, 0x100
and so on). What are they? Could you make them constant?
private void fillLength(byte[] aBuffer, int aOffset, int aLength) {
if(aLength < 0x80) {
aBuffer[aOffset] = (byte) aLength;
} else if (aLength <0x100) {
aBuffer[aOffset] = (byte) 0x81;
aBuffer[aOffset+1] = (byte) aLength;
} else if( aLength < 0x10000) {
aBuffer[aOffset] = (byte) 0x82;
aBuffer[aOffset+1] = (byte) (aLength / 0x100);
aBuffer[aOffset+2] = (byte) (aLength % 0x100);
} else if( aLength < 0x1000000 ) {
aBuffer[aOffset] = (byte) 0x83;
aBuffer[aOffset+1] = (byte) (aLength / 0x10000);
aBuffer[aOffset+2] = (byte) (aLength / 0x100);
aBuffer[aOffset+3] = (byte) (aLength % 0x100);
} else {
throw new IllegalStateException("length ["+aLength+"] out of range (0x1000000)");
}
}
byte[] bytes = new BerTlvBuilder()
.addHex(new BerTag(0x50), "CX89D")
.addHex(new BerTag(0x57), "This is content to generate QR code")
.buildArray();
byte[] bytes = HexUtil.parseHex("");
BerTlvParser parser = new BerTlvParser(LOG);
BerTlvs tlvs = parser.parse(bytes, 0, bytes.length);
Can you please guide me how to parse ? my encrypted string, in above builder I ll get bytes array not encrypted string, please guide me how to use it.
Regards
Vinod
HI,
I'm trying to generate tag FF Ex ( X=1, 2,3.... like -FFE1 /FFE2/FFE3),
when I sent to the builder this tag, the Ex is recognized as constructed tag. and builds it in the wrong way.
Ex ( X=1, 2,3....) is known as a constructed tag? why does the builder recognize it as one?
p.s
the tag FF 12 does not generate this problem
Sir, it's works fine. But I want parse 61 tag what should i do in this case? When i pass 61 tag it will through error.
I suggest to use semantic versioning MAJOR.MINOR.PATCH for package version
Currently Gradle 5.6.4 in Android studio processes dependency version wrong:
'com.payneteasy:ber-tlv:1.0-9' is newer than 'com.payneteasy:ber-tlv:1.0-10'
The following code will lead to an error, if myBerTlv has a value that has over 5120 bytes:
BerTlvBuilder berTlvBuilder = new BerTlvBuilder(myBerTlv.getTag(),
new byte[1000000],
0,
1000000);
byte[] bytes = berTlvBuilder.addBerTlv(myBerTlv);
The exception I got was:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at com.payneteasy.tlv.BerTlvBuilder.addBytes(BerTlvBuilder.java:178)
at com.payneteasy.tlv.BerTlvBuilder.addBytes(BerTlvBuilder.java:162)
at com.payneteasy.tlv.BerTlvBuilder.addBerTlv(BerTlvBuilder.java:196)
at com.payneteasy.tlv.BerTlvBuilder.from(BerTlvBuilder.java:45)
at com.payneteasy.tlv.BerTlvBuilder.addBerTlv(BerTlvBuilder.java:194)
at com.payneteasy.tlv.BerTlvBuilder.from(BerTlvBuilder.java:45)
at com.payneteasy.tlv.BerTlvBuilder.addBerTlv(BerTlvBuilder.java:194)
at com.payneteasy.tlv.BerTlvBuilder.from(BerTlvBuilder.java:45)
at com.payneteasy.tlv.BerTlvBuilder.addBerTlv(BerTlvBuilder.java:194)
at com.payneteasy.tlv.BerTlvBuilder.from(BerTlvBuilder.java:45)
at com.payneteasy.tlv.BerTlvBuilder.addBerTlv(BerTlvBuilder.java:194)
When using the addBerTlv
method, the code eventually calls public BerTlvBuilder(BerTag aTemplate)
, a method that overwrites the custom buffer with the default settings.
The builder has a constructor which accepets BerTlvs
as param:
public BerTlvBuilder(BerTlvs tlvs)
however the BerTlvs
has protected constructor - is this on purpose?
unable to update the value of one Tag
is it intentional?
public BerTlvBuilder(BerTag aTemplate, byte[] aBuffer, int aOffset, int aLength) {
theTemplate = aTemplate;
theBuffer = aBuffer;
thePos = aOffset;
theBufferOffset = aOffset;
}
for(int i=0; i<100; i++) {
ParseResult result = parseWithResult(0, aBuf, offset, aLen-offset);
tlvs.add(result.tlv);
if(result.offset>=aOffset+aLen) {
break;
}
offset = result.offset;
}
i think that code is better
int curOffset;
do {
ParseResult result = parseWithResult(0, aBuf, offset, aLen-offset);
tlvs.add(result.tlv);
if(result.offset>=aOffset+aLen) {
break;
}
curOffset = result.offset;
offset = result.offset;
} while (curOffset<aOffset+aLen);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.