@Test
  public void testPromoteDivert() throws Exception {
    PromoteKeyOperation op =
        new PromoteKeyOperation(
            RuntimeEnvironment.application,
            new ProviderHelper(RuntimeEnvironment.application),
            null,
            null);

    byte[] aid = Hex.decode("D2760001240102000000012345670000");

    PromoteKeyResult result =
        op.execute(new PromoteKeyringParcel(mStaticRing.getMasterKeyId(), aid, null), null);

    Assert.assertTrue("promotion must succeed", result.success());

    {
      CanonicalizedSecretKeyRing ring =
          new ProviderHelper(RuntimeEnvironment.application)
              .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());

      for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
        Assert.assertEquals(
            "all subkeys must be divert-to-card",
            SecretKeyType.DIVERT_TO_CARD,
            key.getSecretKeyTypeSuperExpensive());
        Assert.assertArrayEquals("all subkeys must have correct iv", aid, key.getIv());
      }
    }
  }
  @Test
  public void testPromoteDivertSpecific() throws Exception {
    PromoteKeyOperation op =
        new PromoteKeyOperation(
            RuntimeEnvironment.application,
            new ProviderHelper(RuntimeEnvironment.application),
            null,
            null);

    byte[] aid = Hex.decode("D2760001240102000000012345670000");

    // only promote the first, rest stays dummy
    long keyId = KeyringTestingHelper.getSubkeyId(mStaticRing, 1);

    PromoteKeyResult result =
        op.execute(
            new PromoteKeyringParcel(mStaticRing.getMasterKeyId(), aid, new long[] {keyId}), null);

    Assert.assertTrue("promotion must succeed", result.success());

    {
      CanonicalizedSecretKeyRing ring =
          new ProviderHelper(RuntimeEnvironment.application)
              .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId());

      for (CanonicalizedSecretKey key : ring.secretKeyIterator()) {
        if (key.getKeyId() == keyId) {
          Assert.assertEquals(
              "subkey must be divert-to-card",
              SecretKeyType.DIVERT_TO_CARD,
              key.getSecretKeyTypeSuperExpensive());
          Assert.assertArrayEquals("subkey must have correct iv", aid, key.getIv());
        } else {
          Assert.assertEquals(
              "some subkeys must be gnu dummy",
              SecretKeyType.GNU_DUMMY,
              key.getSecretKeyTypeSuperExpensive());
        }
      }
    }
  }