mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 12:27:58 +01:00
Small improvements
This commit is contained in:
parent
7ff63142b4
commit
4e02996c08
1 changed files with 20 additions and 14 deletions
|
@ -1,8 +1,6 @@
|
||||||
package org.pgpainless.key.generation
|
package org.pgpainless.key.generation
|
||||||
|
|
||||||
import org.bouncycastle.bcpg.attr.ImageAttribute
|
import org.bouncycastle.bcpg.attr.ImageAttribute
|
||||||
import java.security.KeyPair
|
|
||||||
import java.security.KeyPairGenerator
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import org.bouncycastle.openpgp.PGPKeyPair
|
import org.bouncycastle.openpgp.PGPKeyPair
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey
|
import org.bouncycastle.openpgp.PGPPublicKey
|
||||||
|
@ -23,7 +21,6 @@ import org.pgpainless.key.generation.type.eddsa.EdDSACurve
|
||||||
import org.pgpainless.key.generation.type.rsa.RsaLength
|
import org.pgpainless.key.generation.type.rsa.RsaLength
|
||||||
import org.pgpainless.key.generation.type.xdh.XDHSpec
|
import org.pgpainless.key.generation.type.xdh.XDHSpec
|
||||||
import org.pgpainless.policy.Policy
|
import org.pgpainless.policy.Policy
|
||||||
import org.pgpainless.provider.ProviderFactory
|
|
||||||
import org.pgpainless.signature.builder.DirectKeySelfSignatureBuilder
|
import org.pgpainless.signature.builder.DirectKeySelfSignatureBuilder
|
||||||
import org.pgpainless.signature.builder.SelfSignatureBuilder
|
import org.pgpainless.signature.builder.SelfSignatureBuilder
|
||||||
import org.pgpainless.signature.builder.SubkeyBindingSignatureBuilder
|
import org.pgpainless.signature.builder.SubkeyBindingSignatureBuilder
|
||||||
|
@ -35,6 +32,7 @@ import java.io.InputStream
|
||||||
*
|
*
|
||||||
* @param policy policy to ensure algorithm compliance and to determine default algorithms
|
* @param policy policy to ensure algorithm compliance and to determine default algorithms
|
||||||
* @param creationTime creation time for the secret key
|
* @param creationTime creation time for the secret key
|
||||||
|
* @param preferences suite of algorithm preferences and enabled features
|
||||||
*/
|
*/
|
||||||
fun buildV4(
|
fun buildV4(
|
||||||
policy: Policy = PGPainless.getPolicy(),
|
policy: Policy = PGPainless.getPolicy(),
|
||||||
|
@ -53,7 +51,7 @@ fun buildV4(
|
||||||
fun buildV6(
|
fun buildV6(
|
||||||
policy: Policy = PGPainless.getPolicy(),
|
policy: Policy = PGPainless.getPolicy(),
|
||||||
creationTime: Date = Date(),
|
creationTime: Date = Date(),
|
||||||
preferences: AlgorithmSuite = policy.keyGenerationAlgorithmSuite
|
preferences: AlgorithmSuite = AlgorithmSuite.v6AlgorithmSuite
|
||||||
): OpinionatedDefinePrimaryKey.V6 {
|
): OpinionatedDefinePrimaryKey.V6 {
|
||||||
return OpinionatedDefinePrimaryKey.V6(policy, creationTime, preferences)
|
return OpinionatedDefinePrimaryKey.V6(policy, creationTime, preferences)
|
||||||
}
|
}
|
||||||
|
@ -167,7 +165,10 @@ abstract class OpinionatedDefinePrimaryKey<
|
||||||
" for the current public key algorithm policy."
|
" for the current public key algorithm policy."
|
||||||
}
|
}
|
||||||
|
|
||||||
val applier = applyToPrimaryKey ?: { addDirectKeySignature(preferencesSubpackets()) }
|
val applier = applyToPrimaryKey ?: {
|
||||||
|
// Add default direct-key signature containing preferences
|
||||||
|
addDirectKeySignature(preferencesSubpackets())
|
||||||
|
}
|
||||||
|
|
||||||
val unopinionatedSubkeys = unopinionated().setPrimaryKey(type, creationTime, applier)
|
val unopinionatedSubkeys = unopinionated().setPrimaryKey(type, creationTime, applier)
|
||||||
return OpinionatedDefineSubkeys.V4(
|
return OpinionatedDefineSubkeys.V4(
|
||||||
|
@ -234,10 +235,15 @@ abstract class UnopinionatedDefinePrimaryKey<U : UnopinionatedDefineSubkeys>(
|
||||||
creationTime: Date,
|
creationTime: Date,
|
||||||
applyToPrimaryKey: (ApplyToPrimaryKey.() -> PGPKeyPair)?
|
applyToPrimaryKey: (ApplyToPrimaryKey.() -> PGPKeyPair)?
|
||||||
): UnopinionatedDefineSubkeys.V4 {
|
): UnopinionatedDefineSubkeys.V4 {
|
||||||
|
// generate primary key
|
||||||
var primaryKey = OpenPgpKeyPairGenerator.V4().generatePrimaryKey(type, creationTime)
|
var primaryKey = OpenPgpKeyPairGenerator.V4().generatePrimaryKey(type, creationTime)
|
||||||
|
|
||||||
|
// add user-ids and direct-key signatures if requested
|
||||||
if (applyToPrimaryKey != null) {
|
if (applyToPrimaryKey != null) {
|
||||||
primaryKey = ApplyToPrimaryKey.V4(primaryKey, this).applyToPrimaryKey()
|
primaryKey = ApplyToPrimaryKey.V4(primaryKey, this).applyToPrimaryKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return builder for adding subkeys
|
||||||
return UnopinionatedDefineSubkeys.V4(primaryKey, policy, creationTime)
|
return UnopinionatedDefineSubkeys.V4(primaryKey, policy, creationTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,13 +273,13 @@ abstract class DefineSubkeys<B : DefineSubkeys<B>>(val policy: Policy, val creat
|
||||||
*
|
*
|
||||||
* @param type subkey type
|
* @param type subkey type
|
||||||
* @param creationTime creation time of the subkey
|
* @param creationTime creation time of the subkey
|
||||||
* @param function function to apply to the subkey. Used to add binding signatures.
|
* @param applyToSubkey function to apply to the subkey. Used to add binding signatures.
|
||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
abstract fun addSubkey(
|
abstract fun addSubkey(
|
||||||
type: KeyType,
|
type: KeyType,
|
||||||
creationTime: Date = this.creationTime,
|
creationTime: Date = this.creationTime,
|
||||||
function: (ApplyToSubkey.() -> PGPKeyPair)? = null
|
applyToSubkey: (ApplyToSubkey.() -> PGPKeyPair)? = null
|
||||||
): B
|
): B
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -287,6 +293,7 @@ abstract class DefineSubkeys<B : DefineSubkeys<B>>(val policy: Policy, val creat
|
||||||
abstract class OpinionatedDefineSubkeys(policy: Policy, creationTime: Date) :
|
abstract class OpinionatedDefineSubkeys(policy: Policy, creationTime: Date) :
|
||||||
DefineSubkeys<OpinionatedDefineSubkeys>(policy, creationTime) {
|
DefineSubkeys<OpinionatedDefineSubkeys>(policy, creationTime) {
|
||||||
|
|
||||||
|
// unopinionated builder
|
||||||
abstract val unopinionated: UnopinionatedDefineSubkeys
|
abstract val unopinionated: UnopinionatedDefineSubkeys
|
||||||
|
|
||||||
override fun build(): PGPSecretKeyRing = unopinionated.build()
|
override fun build(): PGPSecretKeyRing = unopinionated.build()
|
||||||
|
@ -340,8 +347,8 @@ abstract class OpinionatedDefineSubkeys(policy: Policy, creationTime: Date) :
|
||||||
override fun addSubkey(
|
override fun addSubkey(
|
||||||
type: KeyType,
|
type: KeyType,
|
||||||
creationTime: Date,
|
creationTime: Date,
|
||||||
function: (ApplyToSubkey.() -> PGPKeyPair)?
|
applyToSubkey: (ApplyToSubkey.() -> PGPKeyPair)?
|
||||||
): V6 = apply { unopinionated.addSubkey(type, creationTime, function) }
|
): V6 = apply { unopinionated.addSubkey(type, creationTime, applyToSubkey) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,10 +404,9 @@ abstract class UnopinionatedDefineSubkeys(policy: Policy, creationTime: Date) :
|
||||||
override fun addSubkey(
|
override fun addSubkey(
|
||||||
type: KeyType,
|
type: KeyType,
|
||||||
creationTime: Date,
|
creationTime: Date,
|
||||||
function: (ApplyToSubkey.() -> PGPKeyPair)?
|
applyToSubkey: (ApplyToSubkey.() -> PGPKeyPair)?
|
||||||
): V6 =
|
): V6 {
|
||||||
apply {
|
TODO("Not yet implemented")
|
||||||
// Add Key
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun build(): PGPSecretKeyRing {
|
override fun build(): PGPSecretKeyRing {
|
||||||
|
|
Loading…
Reference in a new issue