Skip to content

Commit

Permalink
Merge pull request jpos#570 from Elias-Terranti/Bug/BerTlvAsciiPackager
Browse files Browse the repository at this point in the history
issue jpos#568: fixed BERTLVAsciiHexPackager  getUninterpretLength always returns 0 with AsciiHex interpreter
  • Loading branch information
ar authored Nov 24, 2023
2 parents f047169 + db2842c commit c6f02d4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,15 @@ public void unpack(ISOComponent m, InputStream in) throws IOException, ISOExcept
private int getUninterpretLength(int length, BinaryInterpreter interpreter) {
if (length > 0) {
int lengthAdjusted = length + length % 2;
return length * (lengthAdjusted / interpreter.getPackedLength(lengthAdjusted));
return (length * lengthAdjusted) / interpreter.getPackedLength(lengthAdjusted);
}
return 0;
}

private int getUninterpretLength(int length, Interpreter interpreter) {
if (length > 0) {
int lengthAdjusted = length + length % 2;
return length * (lengthAdjusted / interpreter.getPackedLength(lengthAdjusted));
return (length * lengthAdjusted) / interpreter.getPackedLength(lengthAdjusted);
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.jpos.tlv.packager.bertlv;
import org.bouncycastle.util.Arrays;
import org.jpos.iso.*;
import org.jpos.tlv.ISOTaggedField;

import org.junit.jupiter.api.*;

public class Bug568BERTLVAsciiHexPackager {

final String HEX_ASCII = "9f2610e18d2a69a45dd09a9f360401839f3708ab34b0bd";

@Test
public void testLenInterpretation() throws ISOException {
final ISOMsg ICC_DATA = new ISOMsg(55);
final BERTLVAsciiHexPackager packager = new BERTLVAsciiHexPackager();
final IFA_LLABINARY fieldPackager = new IFA_LLABINARY();


packager.setFieldPackager(new org.jpos.iso.ISOFieldPackager[]{fieldPackager});
ICC_DATA.setPackager(packager);

ICC_DATA.unpack(HEX_ASCII.getBytes());

ICC_DATA.getChildren().values().forEach
(e -> {
try {
ISOTaggedField field = (ISOTaggedField) e;
final byte[] value = (byte[]) field.getValue();
System.out.println("tag " + field.getTag() + " value " + ISOUtil.hexString(value));
Assertions.
assertFalse(Arrays.isNullOrEmpty(value));

} catch (ISOException ex) {
throw new RuntimeException(ex);
}
});


}

}

0 comments on commit c6f02d4

Please sign in to comment.