Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #568: fixed BERTLVAsciiHexPackager getUninterpretLength always returns 0 with AsciiHex interpreter #570

Merged
merged 4 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
});


}

}

Loading