mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-06-17 00:54:50 +02:00
Rename key generation typealiases
This commit is contained in:
parent
42516d53b8
commit
05cef99f40
|
@ -31,13 +31,13 @@ import org.pgpainless.util.Passphrase
|
||||||
* Function block that is applied to the OpenPGP [PrimaryKeyBuilder]. Within this block, you add
|
* Function block that is applied to the OpenPGP [PrimaryKeyBuilder]. Within this block, you add
|
||||||
* User-IDs, User-Attributes and Direct-Key signatures on the primary key.
|
* User-IDs, User-Attributes and Direct-Key signatures on the primary key.
|
||||||
*/
|
*/
|
||||||
typealias PrimaryKeyBlock = (PrimaryKeyBuilder.() -> Unit)
|
typealias PrimaryKeyBuilderBlock = (PrimaryKeyBuilder.() -> Unit)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function block that is applied to an OpenPGP [SubkeyBuilder]. Here you typically add
|
* Function block that is applied to an OpenPGP [SubkeyBuilder]. Here you typically add
|
||||||
* subkey-binding signatures.
|
* subkey-binding signatures.
|
||||||
*/
|
*/
|
||||||
typealias SubkeyBlock = (SubkeyBuilder.() -> Unit)
|
typealias SubkeyBuilderBlock = (SubkeyBuilder.() -> Unit)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API for generating OpenPGP keys. The API allows to generate keys of different OpenPGP protocol
|
* API for generating OpenPGP keys. The API allows to generate keys of different OpenPGP protocol
|
||||||
|
@ -140,7 +140,7 @@ internal constructor(val policy: Policy, val creationTime: Date, val preferences
|
||||||
*/
|
*/
|
||||||
protected abstract fun invokeOnPrimaryKey(
|
protected abstract fun invokeOnPrimaryKey(
|
||||||
primaryKey: PGPKeyPair,
|
primaryKey: PGPKeyPair,
|
||||||
block: PrimaryKeyBlock?
|
block: PrimaryKeyBuilderBlock?
|
||||||
): PGPKeyPair
|
): PGPKeyPair
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,7 +165,7 @@ internal constructor(val policy: Policy, val creationTime: Date, val preferences
|
||||||
type: KeyType,
|
type: KeyType,
|
||||||
keyFlags: List<KeyFlag>? = listOf(KeyFlag.CERTIFY_OTHER),
|
keyFlags: List<KeyFlag>? = listOf(KeyFlag.CERTIFY_OTHER),
|
||||||
creationTime: Date = this.creationTime,
|
creationTime: Date = this.creationTime,
|
||||||
block: PrimaryKeyBlock? = null
|
block: PrimaryKeyBuilderBlock? = null
|
||||||
): O {
|
): O {
|
||||||
require(type.canCertify) {
|
require(type.canCertify) {
|
||||||
"Primary key cannot use algorithm ${type.algorithm} because it needs to be " +
|
"Primary key cannot use algorithm ${type.algorithm} because it needs to be " +
|
||||||
|
@ -174,14 +174,14 @@ internal constructor(val policy: Policy, val creationTime: Date, val preferences
|
||||||
return doSetPrimaryKey(type, keyFlags, creationTime, block)
|
return doSetPrimaryKey(type, keyFlags, creationTime, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setPrimaryKey(type: KeyType, block: PrimaryKeyBlock?): O =
|
fun setPrimaryKey(type: KeyType, block: PrimaryKeyBuilderBlock?): O =
|
||||||
setPrimaryKey(type, listOf(KeyFlag.CERTIFY_OTHER), this.creationTime, block)
|
setPrimaryKey(type, listOf(KeyFlag.CERTIFY_OTHER), this.creationTime, block)
|
||||||
|
|
||||||
protected abstract fun doSetPrimaryKey(
|
protected abstract fun doSetPrimaryKey(
|
||||||
type: KeyType,
|
type: KeyType,
|
||||||
keyFlags: List<KeyFlag>?,
|
keyFlags: List<KeyFlag>?,
|
||||||
creationTime: Date,
|
creationTime: Date,
|
||||||
block: PrimaryKeyBlock?
|
block: PrimaryKeyBuilderBlock?
|
||||||
): O
|
): O
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -456,7 +456,7 @@ internal constructor(
|
||||||
type: KeyType,
|
type: KeyType,
|
||||||
flags: List<KeyFlag>? = null,
|
flags: List<KeyFlag>? = null,
|
||||||
creationTime: Date = this.creationTime,
|
creationTime: Date = this.creationTime,
|
||||||
block: SubkeyBlock? = null
|
block: SubkeyBuilderBlock? = null
|
||||||
): B =
|
): B =
|
||||||
apply {
|
apply {
|
||||||
sanitizeKeyFlags(type.algorithm, flags)
|
sanitizeKeyFlags(type.algorithm, flags)
|
||||||
|
@ -465,7 +465,7 @@ internal constructor(
|
||||||
var subkey = generateSubkey(type, creationTime)
|
var subkey = generateSubkey(type, creationTime)
|
||||||
|
|
||||||
// Default function block will only set appropriate key flags
|
// Default function block will only set appropriate key flags
|
||||||
val defaultBlock: SubkeyBlock = {
|
val defaultBlock: SubkeyBuilderBlock = {
|
||||||
addBindingSignature(
|
addBindingSignature(
|
||||||
SelfSignatureSubpackets.applyHashed { flags?.let { setKeyFlags(it) } },
|
SelfSignatureSubpackets.applyHashed { flags?.let { setKeyFlags(it) } },
|
||||||
bindingTime = creationTime)
|
bindingTime = creationTime)
|
||||||
|
@ -491,7 +491,7 @@ internal constructor(
|
||||||
* @param block function block
|
* @param block function block
|
||||||
* @return modified subkey
|
* @return modified subkey
|
||||||
*/
|
*/
|
||||||
protected abstract fun invokeOnSubkey(subkey: PGPKeyPair, block: SubkeyBlock?): PGPKeyPair
|
protected abstract fun invokeOnSubkey(subkey: PGPKeyPair, block: SubkeyBuilderBlock?): PGPKeyPair
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate an OpenPGP subkey.
|
* Generate an OpenPGP subkey.
|
||||||
|
|
|
@ -120,7 +120,7 @@ internal constructor(primaryKey: PGPKeyPair, subkey: PGPKeyPair, builder: Define
|
||||||
return OpenPgpKeyPairGenerator.V4().generateSubkey(type, creationTime)
|
return OpenPgpKeyPairGenerator.V4().generateSubkey(type, creationTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun invokeOnSubkey(subkey: PGPKeyPair, block: SubkeyBlock?): PGPKeyPair {
|
override fun invokeOnSubkey(subkey: PGPKeyPair, block: SubkeyBuilderBlock?): PGPKeyPair {
|
||||||
return with(SubkeyBuilderV4(primaryKey, subkey, this)) {
|
return with(SubkeyBuilderV4(primaryKey, subkey, this)) {
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
block()
|
block()
|
||||||
|
@ -224,7 +224,7 @@ internal constructor(policy: Policy, creationTime: Date, preferences: AlgorithmS
|
||||||
type: KeyType,
|
type: KeyType,
|
||||||
keyFlags: List<KeyFlag>?,
|
keyFlags: List<KeyFlag>?,
|
||||||
creationTime: Date,
|
creationTime: Date,
|
||||||
block: PrimaryKeyBlock?
|
block: PrimaryKeyBuilderBlock?
|
||||||
): OpinionatedDefineSubkeysV4 {
|
): OpinionatedDefineSubkeysV4 {
|
||||||
|
|
||||||
// Check key strength
|
// Check key strength
|
||||||
|
@ -325,7 +325,7 @@ internal constructor(policy: Policy, creationTime: Date, preferences: AlgorithmS
|
||||||
type: KeyType,
|
type: KeyType,
|
||||||
keyFlags: List<KeyFlag>?,
|
keyFlags: List<KeyFlag>?,
|
||||||
creationTime: Date,
|
creationTime: Date,
|
||||||
block: PrimaryKeyBlock?
|
block: PrimaryKeyBuilderBlock?
|
||||||
): UnopinionatedDefineSubkeysV4 {
|
): UnopinionatedDefineSubkeysV4 {
|
||||||
|
|
||||||
// Add user-provided signatures
|
// Add user-provided signatures
|
||||||
|
@ -374,7 +374,7 @@ internal constructor(
|
||||||
fun addSigningSubkey(
|
fun addSigningSubkey(
|
||||||
type: KeyType,
|
type: KeyType,
|
||||||
creationTime: Date = this.creationTime,
|
creationTime: Date = this.creationTime,
|
||||||
block: SubkeyBlock? = null
|
block: SubkeyBuilderBlock? = null
|
||||||
): OpinionatedDefineSubkeysV4 {
|
): OpinionatedDefineSubkeysV4 {
|
||||||
return addSubkey(type, listOf(KeyFlag.SIGN_DATA), creationTime, block)
|
return addSubkey(type, listOf(KeyFlag.SIGN_DATA), creationTime, block)
|
||||||
}
|
}
|
||||||
|
@ -387,7 +387,7 @@ internal constructor(
|
||||||
* @param type signing key type
|
* @param type signing key type
|
||||||
* @param block function block to add binding signatures to the subkey
|
* @param block function block to add binding signatures to the subkey
|
||||||
*/
|
*/
|
||||||
fun addSigningSubkey(type: KeyType, block: SubkeyBlock?) =
|
fun addSigningSubkey(type: KeyType, block: SubkeyBuilderBlock?) =
|
||||||
addSigningSubkey(type, this.creationTime, block)
|
addSigningSubkey(type, this.creationTime, block)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -403,7 +403,7 @@ internal constructor(
|
||||||
fun addEncryptionSubkey(
|
fun addEncryptionSubkey(
|
||||||
type: KeyType,
|
type: KeyType,
|
||||||
creationTime: Date = this.creationTime,
|
creationTime: Date = this.creationTime,
|
||||||
block: SubkeyBlock? = null,
|
block: SubkeyBuilderBlock? = null,
|
||||||
): OpinionatedDefineSubkeysV4 {
|
): OpinionatedDefineSubkeysV4 {
|
||||||
return addSubkey(
|
return addSubkey(
|
||||||
type, listOf(KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE), creationTime, block)
|
type, listOf(KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE), creationTime, block)
|
||||||
|
@ -417,7 +417,7 @@ internal constructor(
|
||||||
* @param type encryption key type
|
* @param type encryption key type
|
||||||
* @param block function block to add binding signatures to the subkey
|
* @param block function block to add binding signatures to the subkey
|
||||||
*/
|
*/
|
||||||
fun addEncryptionSubkey(type: KeyType, block: SubkeyBlock?) =
|
fun addEncryptionSubkey(type: KeyType, block: SubkeyBuilderBlock?) =
|
||||||
addEncryptionSubkey(type, this.creationTime, block)
|
addEncryptionSubkey(type, this.creationTime, block)
|
||||||
|
|
||||||
override fun sanitizeHashAlgorithm(algorithm: HashAlgorithm) {
|
override fun sanitizeHashAlgorithm(algorithm: HashAlgorithm) {
|
||||||
|
@ -582,7 +582,7 @@ class PrimaryKeyBuilderV4 internal constructor(keyPair: PGPKeyPair, builder: Def
|
||||||
|
|
||||||
override fun invokeOnPrimaryKey(
|
override fun invokeOnPrimaryKey(
|
||||||
primaryKey: PGPKeyPair,
|
primaryKey: PGPKeyPair,
|
||||||
block: PrimaryKeyBlock?
|
block: PrimaryKeyBuilderBlock?
|
||||||
): PGPKeyPair {
|
): PGPKeyPair {
|
||||||
return with(PrimaryKeyBuilderV4(primaryKey, this)) {
|
return with(PrimaryKeyBuilderV4(primaryKey, this)) {
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
|
|
Loading…
Reference in a new issue