Example usage for org.bouncycastle.bcpg PacketTags SECRET_KEY

List of usage examples for org.bouncycastle.bcpg PacketTags SECRET_KEY

Introduction

In this page you can find the example usage for org.bouncycastle.bcpg PacketTags SECRET_KEY.

Prototype

int SECRET_KEY

To view the source code for org.bouncycastle.bcpg PacketTags SECRET_KEY.

Click Source Link

Usage

From source file:org.sufficientlysecure.keychain.pgp.PgpKeyOperationTest.java

License:Open Source License

@Test
public void testMasterStrip() throws Exception {

    long keyId = ring.getMasterKeyId();
    parcel.mChangeSubKeys.add(new SubkeyChange(keyId, true, false));
    applyModificationWithChecks(parcel, ring, onlyA, onlyB);

    Assert.assertEquals("one extra packet in original", 1, onlyA.size());
    Assert.assertEquals("one extra packet in modified", 1, onlyB.size());

    Assert.assertEquals("old packet must be secret key", PacketTags.SECRET_KEY, onlyA.get(0).tag);
    Assert.assertEquals("new packet must be secret key", PacketTags.SECRET_KEY, onlyB.get(0).tag);

    Packet p = new BCPGInputStream(new ByteArrayInputStream(onlyB.get(0).buf)).readPacket();
    Assert.assertEquals("new packet should have GNU_DUMMY S2K type", S2K.GNU_DUMMY_S2K,
            ((SecretKeyPacket) p).getS2K().getType());
    Assert.assertEquals("new packet should have GNU_DUMMY protection mode 0x1", 0x1,
            ((SecretKeyPacket) p).getS2K().getProtectionMode());
    Assert.assertEquals("new packet secret key data should have length zero", 0,
            ((SecretKeyPacket) p).getSecretKeyData().length);
    Assert.assertNull("new packet should have no iv data", ((SecretKeyPacket) p).getIV());
}

From source file:org.sufficientlysecure.keychain.pgp.UncachedKeyringCanonicalizeTest.java

License:Open Source License

/** Make sure the assumptions made about the generated ring packet structure are valid. */
@Test/*from  w  ww. j a  v  a2s.c o  m*/
public void testGeneratedRingStructure() throws Exception {

    Iterator<RawPacket> it = KeyringTestingHelper.parseKeyring(ring.getEncoded());

    Assert.assertEquals("packet #0 should be secret key", PacketTags.SECRET_KEY, it.next().tag);

    Assert.assertEquals("packet #1 should be user id", PacketTags.USER_ID, it.next().tag);
    Assert.assertEquals("packet #2 should be signature", PacketTags.SIGNATURE, it.next().tag);

    Assert.assertEquals("packet #3 should be user id", PacketTags.USER_ID, it.next().tag);
    Assert.assertEquals("packet #4 should be signature", PacketTags.SIGNATURE, it.next().tag);

    Assert.assertEquals("packet #5 should be user id", PacketTags.USER_ATTRIBUTE, it.next().tag);
    Assert.assertEquals("packet #6 should be signature", PacketTags.SIGNATURE, it.next().tag);

    Assert.assertEquals("packet #7 should be secret subkey", PacketTags.SECRET_SUBKEY, it.next().tag);
    Assert.assertEquals("packet #8 should be signature", PacketTags.SIGNATURE, it.next().tag);

    Assert.assertEquals("packet #9 should be secret subkey", PacketTags.SECRET_SUBKEY, it.next().tag);
    Assert.assertEquals("packet #10 should be signature", PacketTags.SIGNATURE, it.next().tag);

    Assert.assertFalse("exactly 11 packets total", it.hasNext());

    Assert.assertArrayEquals("created keyring should be constant through canonicalization", ring.getEncoded(),
            ring.canonicalize(log, 0).getEncoded());

}