use of com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException in project android_frameworks_opt_telephony by LineageOS.
the class Asn1DecoderTest method testHighTagNumberForm.
@SmallTest
@Test
public void testHighTagNumberForm() throws TagNotFoundException, InvalidAsn1DataException {
String hex = "bf370c5a0a98102100000000000000";
Asn1Decoder decoder = new Asn1Decoder(hex);
assertTrue(decoder.hasNextNode());
Asn1Node root = decoder.nextNode();
assertTrue(root.isConstructed());
assertEquals(0xBF37, root.getTag());
assertEquals(0x0F, root.getEncodedLength());
assertTrue(root.isConstructed());
Asn1Node node = root.getChild(0x5A);
assertEquals(0x0C, node.getEncodedLength());
}
use of com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException in project android_frameworks_opt_telephony by LineageOS.
the class Asn1DecoderTest method testNodeList.
@SmallTest
@Test
public void testNodeList() throws TagNotFoundException, InvalidAsn1DataException {
String hex = "e30c5a0a98102100000000000000e30c5a0a98102100000000000001";
Asn1Decoder decoder = new Asn1Decoder(hex);
assertEquals(0, decoder.getPosition());
assertTrue(decoder.hasNextNode());
Asn1Node firstRoot = decoder.nextNode();
assertEquals(hex.length() / 4, decoder.getPosition());
assertTrue(firstRoot.isConstructed());
assertEquals(0xE3, firstRoot.getTag());
Asn1Node childOfFirst = firstRoot.getChild(0x5A);
assertNotNull(childOfFirst);
assertFalse(childOfFirst.isConstructed());
assertEquals(0x5A, childOfFirst.getTag());
assertTrue(childOfFirst.hasValue());
assertArrayEquals(new byte[] { (byte) 0x98, 0x10, 0x21, 0, 0, 0, 0, 0, 0, 0 }, childOfFirst.asBytes());
assertTrue(decoder.hasNextNode());
Asn1Node secondRoot = decoder.nextNode();
assertEquals(hex.length() / 2, decoder.getPosition());
assertTrue(secondRoot.isConstructed());
assertEquals(0xE3, secondRoot.getTag());
Asn1Node childOfSecond = secondRoot.getChild(0x5A);
assertNotNull(childOfSecond);
assertFalse(childOfSecond.isConstructed());
assertEquals(0x5A, childOfSecond.getTag());
assertTrue(childOfSecond.hasValue());
assertArrayEquals(new byte[] { (byte) 0x98, 0x10, 0x21, 0, 0, 0, 0, 0, 0, 1 }, childOfSecond.asBytes());
assertFalse(decoder.hasNextNode());
assertEquals(hex.length() / 2, decoder.getPosition());
}
use of com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException in project android_frameworks_opt_telephony by LineageOS.
the class Asn1DecoderTest method testMissingData.
@SmallTest
@Test
public void testMissingData() throws TagNotFoundException, InvalidAsn1DataException {
String hex = "e30c5a0a98102100000000000000e30c5a0a98102100000000";
Asn1Decoder decoder = new Asn1Decoder(hex);
assertEquals(0, decoder.getPosition());
assertTrue(decoder.hasNextNode());
Asn1Node firstRoot = decoder.nextNode();
assertEquals(0x0E, decoder.getPosition());
assertTrue(firstRoot.isConstructed());
assertEquals(0xE3, firstRoot.getTag());
Asn1Node childOfFirst = firstRoot.getChild(0x5A);
assertNotNull(childOfFirst);
assertFalse(childOfFirst.isConstructed());
assertEquals(0x5A, childOfFirst.getTag());
assertTrue(childOfFirst.hasValue());
assertArrayEquals(new byte[] { (byte) 0x98, 0x10, 0x21, 0, 0, 0, 0, 0, 0, 0 }, childOfFirst.asBytes());
assertTrue(decoder.hasNextNode());
try {
decoder.nextNode();
fail("Bytes should not be parsed.");
} catch (InvalidAsn1DataException e) {
assertEquals(0xE3, e.getTag());
}
}
use of com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException in project android_frameworks_opt_telephony by LineageOS.
the class Asn1DecoderTest method testNormalOperation.
@SmallTest
@Test
public void testNormalOperation() throws TagNotFoundException, InvalidAsn1DataException {
String hex = "e30c5a0a98102100000000000000";
Asn1Decoder decoder = new Asn1Decoder(hex);
assertEquals(0, decoder.getPosition());
assertTrue(decoder.hasNextNode());
Asn1Node root = decoder.nextNode();
assertEquals(hex.length() / 2, decoder.getPosition());
assertTrue(root.isConstructed());
assertEquals(0xE3, root.getTag());
assertEquals(0x0E, root.getEncodedLength());
assertFalse(root.hasValue());
Asn1Node node = root.getChild(0x5A);
assertEquals(1, root.getChildren().size());
assertEquals(1, root.getChildren(0x5A).size());
assertEquals(node, root.getChildren().get(0));
assertEquals(node, root.getChildren(0x5A).get(0));
assertFalse(node.isConstructed());
assertEquals(0x5A, node.getTag());
assertEquals(0x0C, node.getEncodedLength());
assertTrue(node.hasValue());
assertArrayEquals(new byte[] { (byte) 0x98, 0x10, 0x21, 0, 0, 0, 0, 0, 0, 0 }, node.asBytes());
assertFalse(decoder.hasNextNode());
assertEquals(hex.length() / 2, decoder.getPosition());
}
use of com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException in project android_frameworks_opt_telephony by LineageOS.
the class Asn1NodeTest method testGettersInvalidData.
@SmallTest
@Test
public void testGettersInvalidData() throws TagNotFoundException, InvalidAsn1DataException {
Asn1Node node = Asn1Node.newBuilder(0x30).addChildAsString(0x12, "string").build();
try {
node.getChild(0x12).asInteger();
fail("Should not be parsed.");
} catch (InvalidAsn1DataException e) {
assertEquals(0x12, e.getTag());
}
try {
node.getChild(0x12).asBits();
fail("Should not be parsed.");
} catch (InvalidAsn1DataException e) {
assertEquals(0x12, e.getTag());
}
try {
node.getChild(0x12).asBoolean();
fail("Should not be parsed.");
} catch (InvalidAsn1DataException e) {
assertEquals(0x12, e.getTag());
}
}
Aggregations