Search in sources :

Example 1 with Asn1Node

use of com.android.internal.telephony.uicc.asn1.Asn1Node 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());
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) Asn1Decoder(com.android.internal.telephony.uicc.asn1.Asn1Decoder) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 2 with Asn1Node

use of com.android.internal.telephony.uicc.asn1.Asn1Node 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());
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) Asn1Decoder(com.android.internal.telephony.uicc.asn1.Asn1Decoder) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 3 with Asn1Node

use of com.android.internal.telephony.uicc.asn1.Asn1Node 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());
    }
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) Asn1Decoder(com.android.internal.telephony.uicc.asn1.Asn1Decoder) InvalidAsn1DataException(com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 4 with Asn1Node

use of com.android.internal.telephony.uicc.asn1.Asn1Node 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());
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) Asn1Decoder(com.android.internal.telephony.uicc.asn1.Asn1Decoder) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 5 with Asn1Node

use of com.android.internal.telephony.uicc.asn1.Asn1Node 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());
    }
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) InvalidAsn1DataException(com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

Asn1Node (com.android.internal.telephony.uicc.asn1.Asn1Node)31 Test (org.junit.Test)23 SmallTest (android.test.suitebuilder.annotation.SmallTest)22 Asn1Decoder (com.android.internal.telephony.uicc.asn1.Asn1Decoder)10 RequestBuilder (com.android.internal.telephony.uicc.euicc.apdu.RequestBuilder)6 InvalidAsn1DataException (com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException)3 EuiccProfileInfo (android.service.euicc.EuiccProfileInfo)2 EuiccNotification (android.telephony.euicc.EuiccNotification)2 TagNotFoundException (com.android.internal.telephony.uicc.asn1.TagNotFoundException)2 Nullable (android.annotation.Nullable)1 CarrierIdentifier (android.service.carrier.CarrierIdentifier)1 UiccAccessRule (android.telephony.UiccAccessRule)1 EuiccRulesAuthTable (android.telephony.euicc.EuiccRulesAuthTable)1 TelephonyTest (com.android.internal.telephony.TelephonyTest)1