use of com.android.internal.telephony.uicc.asn1.TagNotFoundException in project android_frameworks_opt_telephony by LineageOS.
the class EuiccCardTest method testAddDeviceCapability.
@Test
public void testAddDeviceCapability() throws InvalidAsn1DataException, TagNotFoundException {
Asn1Node.Builder devCapsBuilder = Asn1Node.newBuilder(Tags.TAG_CTX_COMP_1);
String devCapItem = "gsm,11";
mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
Asn1Node node = devCapsBuilder.build();
assertTrue(node.hasChild(Tags.TAG_CTX_0));
Asn1Node child = node.getChild(Tags.TAG_CTX_0);
assertTrue(Arrays.equals(new byte[] { 11, 0, 0 }, child.asBytes()));
devCapItem = "utran,11";
mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
node = devCapsBuilder.build();
assertTrue(node.hasChild(Tags.TAG_CTX_1));
child = node.getChild(Tags.TAG_CTX_1);
assertTrue(Arrays.equals(new byte[] { 11, 0, 0 }, child.asBytes()));
devCapItem = "cdma1x,1";
mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
node = devCapsBuilder.build();
assertTrue(node.hasChild(Tags.TAG_CTX_2));
child = node.getChild(Tags.TAG_CTX_2);
assertTrue(Arrays.equals(new byte[] { 1, 0, 0 }, child.asBytes()));
devCapItem = "hrpd,1";
mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
node = devCapsBuilder.build();
assertTrue(node.hasChild(Tags.TAG_CTX_3));
child = node.getChild(Tags.TAG_CTX_3);
assertTrue(Arrays.equals(new byte[] { 1, 0, 0 }, child.asBytes()));
devCapItem = "ehrpd,12";
mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
node = devCapsBuilder.build();
assertTrue(node.hasChild(Tags.TAG_CTX_4));
child = node.getChild(Tags.TAG_CTX_4);
assertTrue(Arrays.equals(new byte[] { 12, 0, 0 }, child.asBytes()));
devCapItem = "eutran,11";
mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
node = devCapsBuilder.build();
assertTrue(node.hasChild(Tags.TAG_CTX_5));
child = node.getChild(Tags.TAG_CTX_5);
assertTrue(Arrays.equals(new byte[] { 11, 0, 0 }, child.asBytes()));
devCapItem = "nfc,0";
mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
node = devCapsBuilder.build();
assertTrue(node.hasChild(Tags.TAG_CTX_6));
child = node.getChild(Tags.TAG_CTX_6);
assertTrue(Arrays.equals(new byte[] { 0, 0, 0 }, child.asBytes()));
devCapItem = "crl,0";
mEuiccCard.addDeviceCapability(devCapsBuilder, devCapItem);
node = devCapsBuilder.build();
assertTrue(node.hasChild(Tags.TAG_CTX_7));
child = node.getChild(Tags.TAG_CTX_7);
assertTrue(Arrays.equals(new byte[] { 0, 0, 0 }, child.asBytes()));
// Array length should not be 3.
Asn1Node.Builder devCapsBuilder2 = Asn1Node.newBuilder(Tags.TAG_CTX_COMP_1);
devCapItem = "gsm,1,1";
mEuiccCard.addDeviceCapability(devCapsBuilder2, devCapItem);
node = devCapsBuilder2.build();
assertFalse(node.hasChild(Tags.TAG_CTX_0));
}
use of com.android.internal.telephony.uicc.asn1.TagNotFoundException in project android_frameworks_opt_telephony by LineageOS.
the class Asn1DecoderTest method testEmptyData.
@SmallTest
@Test
public void testEmptyData() throws TagNotFoundException, InvalidAsn1DataException {
String hex = "e3025a00e3025a00";
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[] {}, 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[] {}, childOfSecond.asBytes());
assertFalse(decoder.hasNextNode());
assertEquals(hex.length() / 2, decoder.getPosition());
}
use of com.android.internal.telephony.uicc.asn1.TagNotFoundException in project android_frameworks_opt_telephony by LineageOS.
the class Asn1DecoderTest method testLongFormLength.
@SmallTest
@Test
public void testLongFormLength() throws TagNotFoundException, InvalidAsn1DataException {
String hex = "bf37075a820003010203";
Asn1Decoder decoder = new Asn1Decoder(hex);
assertTrue(decoder.hasNextNode());
Asn1Node root = decoder.nextNode();
assertTrue(root.isConstructed());
assertEquals(0xBF37, root.getTag());
assertEquals(10, root.getEncodedLength());
assertTrue(root.isConstructed());
Asn1Node node = root.getChild(0x5A);
assertEquals(5, node.getEncodedLength());
assertArrayEquals(new byte[] { 1, 2, 3 }, node.asBytes());
}
use of com.android.internal.telephony.uicc.asn1.TagNotFoundException in project android_frameworks_opt_telephony by LineageOS.
the class Asn1NodeTest method testBuilderAndGetters.
@SmallTest
@Test
public void testBuilderAndGetters() throws TagNotFoundException, InvalidAsn1DataException {
Asn1Node node = Asn1Node.newBuilder(0x30).addChildAsInteger(0x11, 1234567).addChildAsString(0x12, "This is a test.").addChild(Asn1Node.newBuilder(0x31).addChildAsBits(0x13, 0xF2344).addChildAsBytes(0x14, new byte[] { -1, 0, -1 })).addChildAsBoolean(0x15, true).addChildAsBoolean(0x16, false).addChildren(IccUtils.hexStringToBytes("13040422C4F01403FF00FF")).build();
assertEquals(54, node.getEncodedLength());
assertEquals(52, node.getDataLength());
final String nodeHex = "3034110312D687120F54686973206973206120746573742E310B13040422C4F0" + "1403FF00FF1501FF16010013040422C4F01403FF00FF";
assertEquals(nodeHex, node.toHex());
assertEquals("3034", node.getHeadAsHex());
assertEquals(1234567, node.getChild(0x11).asInteger());
assertEquals("This is a test.", node.getChild(0x12).asString());
assertEquals(0xF2344, node.getChild(0x31).getChild(0x13).asBits());
assertArrayEquals(new byte[] { -1, 0, -1 }, node.getChild(0x31).getChild(0x14).asBytes());
assertTrue(node.getChild(0x15).asBoolean());
assertFalse(node.getChild(0x16).asBoolean());
assertEquals(0xF2344, node.getChild(0x13).asBits());
assertArrayEquals(new byte[] { -1, 0, -1 }, node.getChild(0x14).asBytes());
}
use of com.android.internal.telephony.uicc.asn1.TagNotFoundException in project android_frameworks_opt_telephony by LineageOS.
the class Asn1NodeTest method testWriteToBytes_IndexOutOfBounds.
@SmallTest
@Test(expected = IndexOutOfBoundsException.class)
public void testWriteToBytes_IndexOutOfBounds() throws TagNotFoundException, InvalidAsn1DataException {
Asn1Node node = Asn1Node.newBuilder(0xBF37).addChildAsString(1, "1").build();
byte[] bytes = new byte[1];
node.writeToBytes(bytes, 0);
}
Aggregations