BigInteger.valueOf(0xFFFFFF) }, };
// positive testcases
for (int i = 0; i < testcase.length; i++) {
try {
BerInputStream in = new BerInputStream(
new ByteArrayInputStream((byte[]) testcase[i][0]));
int expected = ((BigInteger) testcase[i][1]).intValue();
assertEquals(expected, in.getLength());
} catch (IOException e) {
e.printStackTrace();
fail("Testcase: " + i + "\nUnexpected exception." + e);
}
}
// negative testcase
try {
new BerInputStream(new ByteArrayInputStream(new byte[] { 0x30,
(byte) 0x84, 0x01, 0x01, 0x01, 0x01 }));
fail("No expected ASN1Exception");
} catch (ASN1Exception e) {
assertTrue(e.getMessage().startsWith("Too long"));
}
//
// Test for correct internal array reallocation
// Regression for HARMONY-5054
//
// must be greater then buffer initial size (16K)
int arrayLength = 17000;
// 1 byte for tag and 3 for length
byte[] encoding = new byte[arrayLength + 4];
// fill tag and length bytes
encoding[0] = ASN1Constants.TAG_OCTETSTRING;
encoding[1] = (byte) 0x82; // length is encoded in two bytes
encoding[2] = (byte) (arrayLength >> 8);
encoding[3] = (byte) (arrayLength & 0xFF);
BerInputStream in = new BerInputStream(new ByteArrayInputStream(
encoding));
assertEquals(encoding.length, in.getBuffer().length);
}