mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
Allow passing version number to key generator
This commit is contained in:
parent
69d65e763d
commit
626176cdad
4 changed files with 24 additions and 8 deletions
|
@ -10,6 +10,7 @@ import org.bouncycastle.openpgp.PGPKeyRing
|
|||
import org.bouncycastle.openpgp.PGPPublicKeyRing
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
||||
import org.bouncycastle.openpgp.PGPSignature
|
||||
import org.pgpainless.algorithm.OpenPGPKeyVersion
|
||||
import org.pgpainless.decryption_verification.DecryptionBuilder
|
||||
import org.pgpainless.encryption_signing.EncryptionBuilder
|
||||
import org.pgpainless.key.certification.CertifyCertificate
|
||||
|
@ -31,14 +32,20 @@ class PGPainless private constructor() {
|
|||
*
|
||||
* @return templates
|
||||
*/
|
||||
@JvmStatic fun generateKeyRing() = KeyRingTemplates()
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun generateKeyRing(version: OpenPGPKeyVersion = OpenPGPKeyVersion.v4) =
|
||||
KeyRingTemplates(version)
|
||||
|
||||
/**
|
||||
* Build a custom OpenPGP key ring.
|
||||
*
|
||||
* @return builder
|
||||
*/
|
||||
@JvmStatic fun buildKeyRing() = KeyRingBuilder()
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun buildKeyRing(version: OpenPGPKeyVersion = OpenPGPKeyVersion.v4) =
|
||||
KeyRingBuilder(version)
|
||||
|
||||
/**
|
||||
* Read an existing OpenPGP key ring.
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package org.pgpainless.algorithm
|
||||
|
||||
enum class OpenPGPKeyVersion(val version: Int) {
|
||||
v4(4),
|
||||
v6(6),
|
||||
}
|
|
@ -16,6 +16,7 @@ import org.bouncycastle.openpgp.operator.PGPDigestCalculator
|
|||
import org.bouncycastle.util.Strings
|
||||
import org.pgpainless.PGPainless
|
||||
import org.pgpainless.algorithm.KeyFlag
|
||||
import org.pgpainless.algorithm.OpenPGPKeyVersion
|
||||
import org.pgpainless.algorithm.SignatureType
|
||||
import org.pgpainless.bouncycastle.extensions.unlock
|
||||
import org.pgpainless.implementation.ImplementationFactory
|
||||
|
@ -25,7 +26,8 @@ import org.pgpainless.signature.subpackets.SignatureSubpackets
|
|||
import org.pgpainless.signature.subpackets.SignatureSubpacketsHelper
|
||||
import org.pgpainless.util.Passphrase
|
||||
|
||||
class KeyRingBuilder : KeyRingBuilderInterface<KeyRingBuilder> {
|
||||
class KeyRingBuilder(private val version: OpenPGPKeyVersion) :
|
||||
KeyRingBuilderInterface<KeyRingBuilder> {
|
||||
|
||||
private var primaryKeySpec: KeySpec? = null
|
||||
private val subKeySpecs = mutableListOf<KeySpec>()
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.pgpainless.key.generation
|
|||
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
||||
import org.pgpainless.PGPainless.Companion.buildKeyRing
|
||||
import org.pgpainless.algorithm.KeyFlag
|
||||
import org.pgpainless.algorithm.OpenPGPKeyVersion
|
||||
import org.pgpainless.key.generation.KeySpec.Companion.getBuilder
|
||||
import org.pgpainless.key.generation.type.KeyType
|
||||
import org.pgpainless.key.generation.type.eddsa_legacy.EdDSALegacyCurve
|
||||
|
@ -14,7 +15,7 @@ import org.pgpainless.key.generation.type.rsa.RsaLength
|
|||
import org.pgpainless.key.generation.type.xdh_legacy.XDHLegacySpec
|
||||
import org.pgpainless.util.Passphrase
|
||||
|
||||
class KeyRingTemplates {
|
||||
class KeyRingTemplates(private val version: OpenPGPKeyVersion) {
|
||||
|
||||
/**
|
||||
* Generate an RSA OpenPGP key consisting of an RSA primary key used for certification, a
|
||||
|
@ -31,7 +32,7 @@ class KeyRingTemplates {
|
|||
length: RsaLength,
|
||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||
): PGPSecretKeyRing =
|
||||
buildKeyRing()
|
||||
buildKeyRing(version)
|
||||
.apply {
|
||||
setPrimaryKey(getBuilder(KeyType.RSA(length), KeyFlag.CERTIFY_OTHER))
|
||||
addSubkey(getBuilder(KeyType.RSA(length), KeyFlag.SIGN_DATA))
|
||||
|
@ -78,7 +79,7 @@ class KeyRingTemplates {
|
|||
length: RsaLength,
|
||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||
): PGPSecretKeyRing =
|
||||
buildKeyRing()
|
||||
buildKeyRing(version)
|
||||
.apply {
|
||||
setPrimaryKey(
|
||||
getBuilder(
|
||||
|
@ -125,7 +126,7 @@ class KeyRingTemplates {
|
|||
userId: CharSequence?,
|
||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||
): PGPSecretKeyRing =
|
||||
buildKeyRing()
|
||||
buildKeyRing(version)
|
||||
.apply {
|
||||
setPrimaryKey(
|
||||
getBuilder(
|
||||
|
@ -175,7 +176,7 @@ class KeyRingTemplates {
|
|||
userId: CharSequence?,
|
||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||
): PGPSecretKeyRing =
|
||||
buildKeyRing()
|
||||
buildKeyRing(version)
|
||||
.apply {
|
||||
setPrimaryKey(
|
||||
getBuilder(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue