mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 04:17:59 +01:00
Replace all KeyRingTemplates builders with new API
This commit is contained in:
parent
4063fcb6ad
commit
7c00356794
1 changed files with 31 additions and 42 deletions
|
@ -5,9 +5,7 @@
|
||||||
package org.pgpainless.key.generation
|
package org.pgpainless.key.generation
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
||||||
import org.pgpainless.PGPainless.Companion.buildKeyRing
|
|
||||||
import org.pgpainless.algorithm.KeyFlag
|
import org.pgpainless.algorithm.KeyFlag
|
||||||
import org.pgpainless.key.generation.KeySpec.Companion.getBuilder
|
|
||||||
import org.pgpainless.key.generation.type.KeyType
|
import org.pgpainless.key.generation.type.KeyType
|
||||||
import org.pgpainless.key.generation.type.eddsa.EdDSACurve
|
import org.pgpainless.key.generation.type.eddsa.EdDSACurve
|
||||||
import org.pgpainless.key.generation.type.rsa.RsaLength
|
import org.pgpainless.key.generation.type.rsa.RsaLength
|
||||||
|
@ -32,18 +30,16 @@ class KeyRingTemplates {
|
||||||
length: RsaLength,
|
length: RsaLength,
|
||||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||||
): PGPSecretKeyRing =
|
): PGPSecretKeyRing =
|
||||||
buildKeyRing()
|
OpenPgpKeyGenerator.buildV4()
|
||||||
.apply {
|
.setPrimaryKey(KeyType.RSA(length), listOf(KeyFlag.CERTIFY_OTHER)) {
|
||||||
setPrimaryKey(getBuilder(KeyType.RSA(length), KeyFlag.CERTIFY_OTHER))
|
|
||||||
addSubkey(getBuilder(KeyType.RSA(length), KeyFlag.SIGN_DATA))
|
|
||||||
addSubkey(
|
|
||||||
getBuilder(KeyType.RSA(length), KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE))
|
|
||||||
setPassphrase(passphrase)
|
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
addUserId(userId)
|
addUserId(userId)
|
||||||
}
|
}
|
||||||
|
keyPair
|
||||||
}
|
}
|
||||||
.build()
|
.addSigningSubkey(KeyType.RSA(length))
|
||||||
|
.addEncryptionSubkey(KeyType.RSA(length))
|
||||||
|
.build(passphrase)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate an RSA OpenPGP key consisting of an RSA primary key used for certification, a
|
* Generate an RSA OpenPGP key consisting of an RSA primary key used for certification, a
|
||||||
|
@ -71,7 +67,7 @@ class KeyRingTemplates {
|
||||||
*
|
*
|
||||||
* @param userId user id.
|
* @param userId user id.
|
||||||
* @param length length in bits.
|
* @param length length in bits.
|
||||||
* @param password Password of the key. Can be empty for unencrypted keys.
|
* @param passphrase Password of the key. Can be empty for unencrypted keys.
|
||||||
* @return {@link PGPSecretKeyRing} containing the KeyPair.
|
* @return {@link PGPSecretKeyRing} containing the KeyPair.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
|
@ -80,20 +76,20 @@ class KeyRingTemplates {
|
||||||
length: RsaLength,
|
length: RsaLength,
|
||||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||||
): PGPSecretKeyRing =
|
): PGPSecretKeyRing =
|
||||||
buildKeyRing()
|
OpenPgpKeyGenerator.buildV4()
|
||||||
.apply {
|
.setPrimaryKey(
|
||||||
setPrimaryKey(
|
KeyType.RSA(length),
|
||||||
getBuilder(
|
listOf(
|
||||||
KeyType.RSA(length),
|
KeyFlag.CERTIFY_OTHER,
|
||||||
KeyFlag.CERTIFY_OTHER,
|
KeyFlag.SIGN_DATA,
|
||||||
KeyFlag.SIGN_DATA,
|
KeyFlag.ENCRYPT_COMMS,
|
||||||
KeyFlag.ENCRYPT_COMMS))
|
KeyFlag.ENCRYPT_STORAGE)) {
|
||||||
setPassphrase(passphrase)
|
if (userId != null) {
|
||||||
if (userId != null) {
|
addUserId(userId)
|
||||||
addUserId(userId.toString())
|
}
|
||||||
|
keyPair
|
||||||
}
|
}
|
||||||
}
|
.build(passphrase)
|
||||||
.build()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a simple RSA KeyPair of length {@code length} with user-id {@code userId}. The
|
* Creates a simple RSA KeyPair of length {@code length} with user-id {@code userId}. The
|
||||||
|
@ -128,24 +124,17 @@ class KeyRingTemplates {
|
||||||
userId: CharSequence?,
|
userId: CharSequence?,
|
||||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||||
): PGPSecretKeyRing =
|
): PGPSecretKeyRing =
|
||||||
buildKeyRing()
|
OpenPgpKeyGenerator.buildV4()
|
||||||
.apply {
|
.setPrimaryKey(
|
||||||
setPrimaryKey(
|
KeyType.EDDSA(EdDSACurve._Ed25519),
|
||||||
getBuilder(
|
listOf(KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA)) {
|
||||||
KeyType.EDDSA(EdDSACurve._Ed25519),
|
if (userId != null) {
|
||||||
KeyFlag.CERTIFY_OTHER,
|
addUserId(userId)
|
||||||
KeyFlag.SIGN_DATA))
|
}
|
||||||
addSubkey(
|
keyPair
|
||||||
getBuilder(
|
|
||||||
KeyType.XDH(XDHSpec._X25519),
|
|
||||||
KeyFlag.ENCRYPT_STORAGE,
|
|
||||||
KeyFlag.ENCRYPT_COMMS))
|
|
||||||
setPassphrase(passphrase)
|
|
||||||
if (userId != null) {
|
|
||||||
addUserId(userId.toString())
|
|
||||||
}
|
}
|
||||||
}
|
.addEncryptionSubkey(KeyType.XDH(XDHSpec._X25519))
|
||||||
.build()
|
.build(passphrase)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a key ring consisting of an ed25519 EdDSA primary key and a X25519 XDH subkey. The
|
* Creates a key ring consisting of an ed25519 EdDSA primary key and a X25519 XDH subkey. The
|
||||||
|
@ -153,7 +142,7 @@ class KeyRingTemplates {
|
||||||
* used for encryption and decryption of messages.
|
* used for encryption and decryption of messages.
|
||||||
*
|
*
|
||||||
* @param userId user-id
|
* @param userId user-id
|
||||||
* @param passphrase Password of the private key. Can be null or blank for an unencrypted key.
|
* @param password Password of the private key. Can be null or blank for an unencrypted key.
|
||||||
* @return {@link PGPSecretKeyRing} containing the key pairs.
|
* @return {@link PGPSecretKeyRing} containing the key pairs.
|
||||||
*/
|
*/
|
||||||
fun simpleEcKeyRing(userId: CharSequence?, password: String?): PGPSecretKeyRing =
|
fun simpleEcKeyRing(userId: CharSequence?, password: String?): PGPSecretKeyRing =
|
||||||
|
|
Loading…
Reference in a new issue