Skip to content

Commit

Permalink
Bugfix in IFA_BITMAP handling third bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Apr 8, 2014
1 parent cce6a27 commit f29e7cf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
11 changes: 8 additions & 3 deletions jpos/src/main/java/org/jpos/iso/IFA_BITMAP.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ public IFA_BITMAP(int len, String description) {
* @exception ISOException
*/
public byte[] pack (ISOComponent c) throws ISOException {
byte[] b = ISOUtil.bitSet2byte ((BitSet) c.getValue());
return ISOUtil.hexString(b).getBytes();
BitSet b = (BitSet) c.getValue();
int len =
getLength() >= 8 ?
(((b.length()+62)>>6)<<3) : getLength();
return ISOUtil.hexString(ISOUtil.bitSet2byte (b, len)).getBytes();
}

public int getMaxPackedLength() {
Expand All @@ -68,8 +71,10 @@ public int unpack (ISOComponent c, byte[] b, int offset)
BitSet bmap = ISOUtil.hex2BitSet (b, offset, getLength() << 3);
c.setValue(bmap);
len = (bmap.get(1)) ? 128 : 64; /* changed by Hani */
if (getLength() > 16 && bmap.get(65))
if (getLength() > 16 && bmap.get(65)) {
len = 192;
bmap.clear(65);
}
return (len >> 2);
}
public void unpack (ISOComponent c, InputStream in)
Expand Down
6 changes: 6 additions & 0 deletions jpos/src/main/java/org/jpos/iso/ISOUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,12 @@ public static BitSet hex2BitSet (byte[] b, int offset, int maxBits) {
int len = maxBits > 64?
((Character.digit((char)b[offset],16) & 0x08) == 8 ? 128 : 64) :
maxBits;
if (len > 64 && maxBits > 128 &&
b.length > offset+16 &&
(Character.digit((char)b[offset+16],16) & 0x08) == 8)
{
len = 192;
}
BitSet bmap = new BitSet (len);
for (int i=0; i<len; i++) {
int digit = Character.digit((char)b[offset + (i >> 2)], 16);
Expand Down
9 changes: 4 additions & 5 deletions jpos/src/test/java/org/jpos/iso/IFA_BITMAPTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public void setUp() {
thirtytwoBytes = new IFA_BITMAP(32,"32 byte bitmap");
fortyeightBytes = new IFA_BITMAP(48,"48 byte bitmap");

inBytes = "8F81421FF12418F18F81421FF12418F18F81421FF12418F1".getBytes();
sixteenByteBitMapIn32Bytes = "7F81421FF12418F18F81421FF12418F18F81421FF12418F1".getBytes();
thirtytwoByteBitMapIn48Bytes = "8F81421FF12418F17F81421FF12418F18F81421FF12418F1".getBytes();
sixteenByteBitMapIn48Bytes = "7F81421FF12418F17F81421FF12418F18F81421FF12418F1".getBytes();
inBytes = "8F81421FF12418F18F81421FF12418F18081421FF12418F1".getBytes();
sixteenByteBitMapIn32Bytes = "7F81421FF12418F18F81421FF12418F18081421FF12418F1".getBytes();
thirtytwoByteBitMapIn48Bytes = "8F81421FF12418F17F81421FF12418F18081421FF12418F1".getBytes();
sixteenByteBitMapIn48Bytes = "7F81421FF12418F17F81421FF12418F18081421FF12418F1".getBytes();
in = ISOUtil.hexdump(inBytes);

}
Expand Down Expand Up @@ -208,5 +208,4 @@ public void setUp() {
assertEquals("48 Byte (16 bytes used) bitmap pack should reflect unpack",ISOUtil.hexString(sixteenByteBitMapIn48Bytes,0,16),ISOUtil.hexString(outBytes));

}

}
24 changes: 23 additions & 1 deletion jpos/src/test/java/org/jpos/iso/ISOUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,28 @@ public void testBitSet2byte3() throws Throwable {
assertEquals("result.length", 0, result.length);
}

@Test
public void testBitSetByteHexInteroperability() throws Throwable {
BitSet bs = new BitSet();
bs.set(1);
bs.set(63);
bs.set(127);
bs.set(191);
byte[] b = ISOUtil.bitSet2byte(bs);
BitSet bs1 = ISOUtil.byte2BitSet(b, 0, 192);
BitSet bs2 = ISOUtil.hex2BitSet(ISOUtil.hexString(b).getBytes(), 0, 192);
assertEquals("BitSets should be equal", bs1, bs2);
}

@Test
public void testBitSetByteHexInteroperability2() throws Throwable {
byte[] b = ISOUtil.hex2byte("F23C04800EE0000080000000000000000000380000000000");
BitSet bs1 = ISOUtil.byte2BitSet(b, 0, 192);
BitSet bs2 = ISOUtil.hex2BitSet (ISOUtil.hexString(b).getBytes(), 0, 192);
assertEquals("BitSets should be equal", bs1, bs2);
assertEquals("Image matches", ISOUtil.hexString(b), ISOUtil.hexString(ISOUtil.bitSet2byte(bs1)));
}

@Test(expected = NullPointerException.class)
public void testBitSet2byteThrowsNullPointerException() throws Throwable {
ISOUtil.bitSet2byte(null);
Expand Down Expand Up @@ -2466,7 +2488,7 @@ public void testHex2BitSet1() throws Throwable {
public void testHex2BitSet10() throws Throwable {
byte[] b = new byte[80];
BitSet result = ISOUtil.hex2BitSet(b, 0, 1000);
assertEquals("result.size()", 256, result.size());
assertEquals("result.size()", 384, result.size());
}

@Test
Expand Down

0 comments on commit f29e7cf

Please sign in to comment.