1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-24 11:57:59 +01:00

Port KeyRingTemplates.modernKeyRing() to new generator API. Fails test

This commit is contained in:
Paul Schaub 2024-02-03 13:17:02 +01:00
parent f08981b78c
commit acd9566dbd
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -5,6 +5,7 @@
package org.pgpainless.key.generation
import org.bouncycastle.openpgp.PGPSecretKeyRing
import org.pgpainless.PGPainless
import org.pgpainless.PGPainless.Companion.buildKeyRing
import org.pgpainless.algorithm.KeyFlag
import org.pgpainless.key.generation.KeySpec.Companion.getBuilder
@ -12,6 +13,7 @@ import org.pgpainless.key.generation.type.KeyType
import org.pgpainless.key.generation.type.eddsa.EdDSACurve
import org.pgpainless.key.generation.type.rsa.RsaLength
import org.pgpainless.key.generation.type.xdh.XDHSpec
import org.pgpainless.key.protection.SecretKeyRingProtector
import org.pgpainless.util.Passphrase
class KeyRingTemplates {
@ -177,21 +179,18 @@ class KeyRingTemplates {
userId: CharSequence?,
passphrase: Passphrase = Passphrase.emptyPassphrase()
): PGPSecretKeyRing =
buildKeyRing()
GenerateOpenPgpKey(PGPainless.getPolicy())
.buildV4Key(KeyType.EDDSA(EdDSACurve._Ed25519))
.apply {
setPrimaryKey(getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.CERTIFY_OTHER))
addSubkey(
getBuilder(
KeyType.XDH(XDHSpec._X25519),
KeyFlag.ENCRYPT_COMMS,
KeyFlag.ENCRYPT_STORAGE))
addSubkey(getBuilder(KeyType.EDDSA(EdDSACurve._Ed25519), KeyFlag.SIGN_DATA))
setPassphrase(passphrase)
if (userId != null) {
addUserId(userId)
}
addEncryptionSubkey(KeyType.XDH(XDHSpec._X25519))
addSigningSubkey(KeyType.EDDSA(EdDSACurve._Ed25519))
}
.build()
.build(
if (passphrase.isEmpty) SecretKeyRingProtector.unprotectedKeys()
else SecretKeyRingProtector.unlockAnyKeyWith(passphrase))
/**
* Generate a modern PGP key ring consisting of an ed25519 EdDSA primary key which is used to