1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-13 20:29:39 +02:00

More code cleanup and tests

This commit is contained in:
Paul Schaub 2021-01-21 14:35:33 +01:00
parent bd9a580600
commit c35154813a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 38 additions and 20 deletions

View file

@ -33,6 +33,8 @@ import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.util.Passphrase;
public class KeyRingInfoTest {
@ -79,4 +81,28 @@ public class KeyRingInfoTest {
assertEquals(revocationDate.getTime(), rInfo.getRevocationDate().getTime(), 1000);
assertEquals(revocationDate.getTime(), rInfo.getLastModified().getTime(), 1000);
}
@Test
public void testIsFullyDecrypted() throws IOException, PGPException {
PGPSecretKeyRing secretKeys = TestKeys.getEmilSecretKeyRing();
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);
assertTrue(info.isFullyDecrypted());
secretKeys = PGPainless.modifyKeyRing(secretKeys)
.changePassphraseFromOldPassphrase(null)
.withSecureDefaultSettings()
.toNewPassphrase(Passphrase.fromPassword("sw0rdf1sh"))
.done();
info = PGPainless.inspectKeyRing(secretKeys);
assertFalse(info.isFullyDecrypted());
}
@Test
public void testGetSecretKey() throws IOException, PGPException {
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
}
}

View file

@ -36,6 +36,8 @@ import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.generation.KeySpec;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.rsa.RsaLength;
@ -133,4 +135,14 @@ public class BCUtilTest {
PGPSecretKeyRing cleaned = BCUtil.removeUnassociatedKeysFromKeyRing(alice_mallory, alice.getPublicKey());
assertNull(cleaned.getSecretKey(subKey.getKeyID()));
}
@Test
public void getMasterKeyFromRingTest() throws IOException, PGPException {
PGPSecretKeyRing secretKeys = TestKeys.getCryptieSecretKeyRing();
PGPPublicKey primaryKey = BCUtil.getMasterKeyFrom(secretKeys);
assertNotNull(primaryKey);
assertEquals(TestKeys.CRYPTIE_FINGERPRINT, new OpenPgpV4Fingerprint(primaryKey));
}
}