mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 02:39:39 +02:00
Change return type of KeyRingBuilder.build() to OpenPGPKey
This commit is contained in:
parent
f5e9b0602e
commit
932c7d878b
74 changed files with 319 additions and 188 deletions
|
@ -9,7 +9,7 @@ import java.lang.RuntimeException
|
|||
import java.security.InvalidAlgorithmParameterException
|
||||
import java.security.NoSuchAlgorithmException
|
||||
import org.bouncycastle.openpgp.PGPException
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
||||
import org.bouncycastle.openpgp.api.OpenPGPKey
|
||||
import org.pgpainless.PGPainless
|
||||
import org.pgpainless.algorithm.KeyFlag
|
||||
import org.pgpainless.key.generation.KeyRingBuilder
|
||||
|
@ -50,11 +50,11 @@ class GenerateKeyImpl : GenerateKey {
|
|||
return object : Ready() {
|
||||
override fun writeTo(outputStream: OutputStream) {
|
||||
if (armor) {
|
||||
val armorOut = ArmorUtils.toAsciiArmoredStream(key, outputStream)
|
||||
key.encode(armorOut)
|
||||
val armorOut = ArmorUtils.toAsciiArmoredStream(key.pgpKeyRing, outputStream)
|
||||
key.pgpKeyRing.encode(armorOut)
|
||||
armorOut.close()
|
||||
} else {
|
||||
key.encode(outputStream)
|
||||
key.pgpKeyRing.encode(outputStream)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ class GenerateKeyImpl : GenerateKey {
|
|||
userIds: Set<String>,
|
||||
passphrase: Passphrase,
|
||||
signingOnly: Boolean
|
||||
): PGPSecretKeyRing {
|
||||
): OpenPGPKey {
|
||||
val keyBuilder: KeyRingBuilder =
|
||||
when (profile) {
|
||||
CURVE25519_PROFILE.name ->
|
||||
|
|
|
@ -17,7 +17,10 @@ public class ArmorTest {
|
|||
|
||||
@Test
|
||||
public void armor() throws IOException {
|
||||
byte[] data = PGPainless.generateKeyRing().modernKeyRing("Alice").getEncoded();
|
||||
byte[] data = PGPainless.generateKeyRing()
|
||||
.modernKeyRing("Alice")
|
||||
.getPGPSecretKeyRing()
|
||||
.getEncoded();
|
||||
byte[] knownGoodArmor = ArmorUtils.toAsciiArmoredString(data)
|
||||
.replace("Version: PGPainless\n", "") // armor command does not add version anymore
|
||||
.getBytes(StandardCharsets.UTF_8);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
package org.pgpainless.sop;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -20,8 +19,6 @@ import sop.exception.SOPGPException;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
|
@ -35,12 +32,13 @@ public class IncapableKeysTest {
|
|||
private static final SOP sop = new SOPImpl();
|
||||
|
||||
@BeforeAll
|
||||
public static void generateKeys() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException {
|
||||
public static void generateKeys() throws IOException {
|
||||
PGPSecretKeyRing key = PGPainless.buildKeyRing()
|
||||
.addSubkey(KeySpec.getBuilder(KeyType.ECDH(EllipticCurve._P256), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE))
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER))
|
||||
.addUserId("Non Signing <non@signing.key>")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
nonSigningKey = ArmorUtils.toAsciiArmoredString(key).getBytes(StandardCharsets.UTF_8);
|
||||
nonSigningCert = sop.extractCert().key(nonSigningKey).getBytes();
|
||||
|
||||
|
@ -48,7 +46,8 @@ public class IncapableKeysTest {
|
|||
.addSubkey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.SIGN_DATA))
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER))
|
||||
.addUserId("Non Encryption <non@encryption.key>")
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
nonEncryptionKey = ArmorUtils.toAsciiArmoredString(key).getBytes(StandardCharsets.UTF_8);
|
||||
nonEncryptionCert = sop.extractCert().key(nonEncryptionKey).getBytes();
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@ import sop.testsuite.operation.ChangeKeyPasswordTest;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
@ -32,12 +30,13 @@ public class PGPainlessChangeKeyPasswordTest extends ChangeKeyPasswordTest {
|
|||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideInstances")
|
||||
public void changePasswordOfKeyWithSeparateSubkeyPasswords(SOP sop) throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||
public void changePasswordOfKeyWithSeparateSubkeyPasswords(SOP sop) throws IOException, PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.buildKeyRing()
|
||||
.setPrimaryKey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER))
|
||||
.addSubkey(KeySpec.getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.SIGN_DATA))
|
||||
.addSubkey(KeySpec.getBuilder(KeyType.XDH_LEGACY(XDHLegacySpec._X25519), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE))
|
||||
.build();
|
||||
.build()
|
||||
.getPGPSecretKeyRing();
|
||||
Iterator<PGPPublicKey> keys = secretKeys.getPublicKeys();
|
||||
long primaryKeyId = keys.next().getKeyID();
|
||||
long signingKeyId = keys.next().getKeyID();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue