Search in sources :

Example 6 with TagNotFoundException

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

the class Asn1NodeTest method testNonExitingChildren.

@SmallTest
@Test
public void testNonExitingChildren() throws TagNotFoundException, InvalidAsn1DataException {
    Asn1Node node = Asn1Node.newBuilder(0x3F34).addChild(Asn1Node.newBuilder(0x34)).addChild(Asn1Node.newBuilder(0x35).addChild(Asn1Node.newBuilder(0x36))).addChildAsInteger(0x11, 123).build();
    assertEquals(0, node.getChild(0x34).getChildren(0x37).size());
    assertEquals(0, node.getChildren(0x37).size());
    assertEquals(0, node.getChild(0x11).getChildren(0x37).size());
    assertEquals(0, node.getChild(0x11).getChildren().size());
    try {
        node.getChild(0x35).getChild(0x37);
        fail("0x37 should not exist.");
    } catch (TagNotFoundException e) {
        assertEquals(0x37, e.getTag());
    }
    try {
        node.getChild(0x35, 0x37);
        fail("0x37 should not exist.");
    } catch (TagNotFoundException e) {
        assertEquals(0x37, e.getTag());
    }
    try {
        node.getChild(0x11).getChild(0x37);
        fail("0x37 should not exist.");
    } catch (TagNotFoundException e) {
        assertEquals(0x37, e.getTag());
    }
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) TagNotFoundException(com.android.internal.telephony.uicc.asn1.TagNotFoundException) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 7 with TagNotFoundException

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

the class Asn1NodeTest method testLongFormLength.

@SmallTest
@Test
public void testLongFormLength() throws TagNotFoundException, InvalidAsn1DataException {
    Asn1Node node = Asn1Node.newBuilder(0xBF37).addChildAsBytes(0x5A, new byte[257]).build();
    assertEquals(266, node.getEncodedLength());
    assertEquals(261, node.getDataLength());
    assertEquals(257, node.getChild(0x5A).getDataLength());
    assertEquals("BF37820105", node.getHeadAsHex());
    byte[] expected = new byte[266];
    System.arraycopy(IccUtils.hexStringToBytes("BF378201055A820101"), 0, expected, 0, 9);
    byte[] actual = new byte[266];
    node.writeToBytes(actual, 0);
    assertArrayEquals(expected, actual);
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 8 with TagNotFoundException

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

the class Asn1NodeTest method testChildren.

@SmallTest
@Test
public void testChildren() throws TagNotFoundException, InvalidAsn1DataException {
    Asn1Node node = Asn1Node.newBuilder(0x3F34).addChild(Asn1Node.newBuilder(0x35).addChild(Asn1Node.newBuilder(0x36))).addChild(Asn1Node.newBuilder(0x35)).addChild(Asn1Node.newBuilder(0x37)).build();
    assertEquals(0x3F34, node.getTag());
    assertEquals(3, node.getChildren().size());
    assertEquals(0x35, node.getChildren().get(0).getTag());
    assertEquals(0x35, node.getChildren().get(1).getTag());
    assertEquals(0x37, node.getChildren().get(2).getTag());
    assertEquals(2, node.getChildren(0x35).size());
    assertEquals(0x35, node.getChildren(0x35).get(0).getTag());
    assertEquals(0x35, node.getChildren(0x35).get(1).getTag());
    assertEquals(1, node.getChild(0x35).getChildren().size());
    assertEquals(0, node.getChildren().get(1).getChildren().size());
    assertEquals(0x36, node.getChild(0x35).getChildren().get(0).getTag());
    assertTrue(node.hasChild(0x35, 0x36));
    assertFalse(node.hasChild(0x38, 0x39));
    assertTrue(node.getChild(0x35).hasChild(0x36));
    assertFalse(node.getChild(0x35).hasChild(0x39));
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 9 with TagNotFoundException

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

the class EuiccCard method buildUiccAccessRule.

@Nullable
private static UiccAccessRule[] buildUiccAccessRule(List<Asn1Node> nodes) throws InvalidAsn1DataException, TagNotFoundException {
    if (nodes.isEmpty()) {
        return null;
    }
    int count = nodes.size();
    UiccAccessRule[] rules = new UiccAccessRule[count];
    for (int i = 0; i < count; i++) {
        Asn1Node node = nodes.get(i);
        Asn1Node refDoNode = node.getChild(Tags.TAG_REF_DO);
        byte[] signature = refDoNode.getChild(Tags.TAG_DEVICE_APP_ID_REF_DO).asBytes();
        String packageName = null;
        if (refDoNode.hasChild(Tags.TAG_PKG_REF_DO)) {
            packageName = refDoNode.getChild(Tags.TAG_PKG_REF_DO).asString();
        }
        long accessType = 0;
        if (node.hasChild(Tags.TAG_AR_DO, Tags.TAG_PERM_AR_DO)) {
            Asn1Node permArDoNode = node.getChild(Tags.TAG_AR_DO, Tags.TAG_PERM_AR_DO);
            accessType = permArDoNode.asRawLong();
        }
        rules[i] = new UiccAccessRule(signature, packageName, accessType);
    }
    return rules;
}
Also used : UiccAccessRule(android.telephony.UiccAccessRule) Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) Nullable(android.annotation.Nullable)

Example 10 with TagNotFoundException

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

the class EuiccSpecVersion method fromOpenChannelResponse.

/**
 * Parses the response of opening a logical channel to get spec version of the eUICC card.
 *
 * @return Parsed spec version. If any error is encountered, null will be returned.
 */
public static EuiccSpecVersion fromOpenChannelResponse(byte[] response) {
    Asn1Node node;
    try {
        Asn1Decoder decoder = new Asn1Decoder(response);
        if (!decoder.hasNextNode()) {
            return null;
        }
        node = decoder.nextNode();
    } catch (InvalidAsn1DataException e) {
        Rlog.e(LOG_TAG, "Cannot parse the select response of ISD-R.", e);
        return null;
    }
    try {
        byte[] versionType;
        if (node.getTag() == TAG_ISD_R_APP_TEMPLATE) {
            versionType = node.getChild(TAG_VERSION).asBytes();
        } else {
            versionType = node.getChild(TAG_ISD_R_APP_TEMPLATE, TAG_VERSION).asBytes();
        }
        if (versionType.length == 3) {
            return new EuiccSpecVersion(versionType);
        } else {
            Rlog.e(LOG_TAG, "Cannot parse select response of ISD-R: " + node.toHex());
        }
    } catch (InvalidAsn1DataException | TagNotFoundException e) {
        Rlog.e(LOG_TAG, "Cannot parse select response of ISD-R: " + node.toHex());
    }
    return null;
}
Also used : Asn1Node(com.android.internal.telephony.uicc.asn1.Asn1Node) TagNotFoundException(com.android.internal.telephony.uicc.asn1.TagNotFoundException) Asn1Decoder(com.android.internal.telephony.uicc.asn1.Asn1Decoder) InvalidAsn1DataException(com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException)

Aggregations

Asn1Node (com.android.internal.telephony.uicc.asn1.Asn1Node)16 Test (org.junit.Test)14 SmallTest (android.test.suitebuilder.annotation.SmallTest)13 Asn1Decoder (com.android.internal.telephony.uicc.asn1.Asn1Decoder)7 InvalidAsn1DataException (com.android.internal.telephony.uicc.asn1.InvalidAsn1DataException)3 TagNotFoundException (com.android.internal.telephony.uicc.asn1.TagNotFoundException)2 Nullable (android.annotation.Nullable)1 UiccAccessRule (android.telephony.UiccAccessRule)1 TelephonyTest (com.android.internal.telephony.TelephonyTest)1