Search in sources :

Example 1 with Asn1Decoder

use of com.android.internal.telephony.uicc.asn1.Asn1Decoder 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 Asn1Decoder

use of com.android.internal.telephony.uicc.asn1.Asn1Decoder 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 Asn1Decoder

use of com.android.internal.telephony.uicc.asn1.Asn1Decoder 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 Asn1Decoder

use of com.android.internal.telephony.uicc.asn1.Asn1Decoder 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 Asn1Decoder

use of com.android.internal.telephony.uicc.asn1.Asn1Decoder in project android_frameworks_opt_telephony by LineageOS.

the class Asn1NodeTest method testWriteToBytes.

@SmallTest
@Test
public void testWriteToBytes() throws InvalidAsn1DataException {
    final String nodeHex = "3031110312D687120F54686973206973206120746573742E310B13040422C4F0" + "1403FF00FF1501FF13040422C4F01403FF00FF";
    Asn1Node node = new Asn1Decoder(nodeHex).nextNode();
    // Writes the bytes before children accessed.
    assertEquals(nodeHex, node.toHex());
    // Writes the bytes after children accessed.
    node.getChildren();
    assertEquals(nodeHex, node.toHex());
}
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)

Aggregations

Asn1Decoder (com.android.internal.telephony.uicc.asn1.Asn1Decoder)10 Asn1Node (com.android.internal.telephony.uicc.asn1.Asn1Node)10 SmallTest (android.test.suitebuilder.annotation.SmallTest)7 Test (org.junit.Test)7 EuiccProfileInfo (android.service.euicc.EuiccProfileInfo)2 InvalidAsn1DataException (com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException)2 RequestBuilder (com.android.internal.telephony.uicc.euicc.apdu.RequestBuilder)2 TagNotFoundException (com.android.internal.telephony.uicc.asn1.TagNotFoundException)1