mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 04:17:59 +01:00
Auto-adjust primaryUserId
This commit is contained in:
parent
acd9566dbd
commit
9cea63529f
1 changed files with 27 additions and 1 deletions
|
@ -114,6 +114,12 @@ open class GenerateOpenPgpKey(
|
||||||
primaryFlags?.let { setKeyFlags(*it.toTypedArray()) }
|
primaryFlags?.let { setKeyFlags(*it.toTypedArray()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a direct-key signature to the primary key. If this method is called, the automatic
|
||||||
|
* addition of a direct-key signature in the final build-step will be omitted.
|
||||||
|
*
|
||||||
|
* @param subpacketsCallback callback to modify the subpackets of the direct-key signature.
|
||||||
|
*/
|
||||||
fun directKeySignature(
|
fun directKeySignature(
|
||||||
subpacketsCallback: SelfSignatureSubpackets.Callback = SelfSignatureSubpackets.nop()
|
subpacketsCallback: SelfSignatureSubpackets.Callback = SelfSignatureSubpackets.nop()
|
||||||
) = apply {
|
) = apply {
|
||||||
|
@ -122,6 +128,10 @@ open class GenerateOpenPgpKey(
|
||||||
subpacketsCallback = preferencesCallback.then(subpacketsCallback))
|
subpacketsCallback = preferencesCallback.then(subpacketsCallback))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this method is called, the automatic addition of a direct-key signature in the final
|
||||||
|
* build-step will be omitted.
|
||||||
|
*/
|
||||||
fun noDirectKeySignature() = apply { addDirectKeySignature = false }
|
fun noDirectKeySignature() = apply { addDirectKeySignature = false }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,8 +147,24 @@ open class GenerateOpenPgpKey(
|
||||||
userId: CharSequence,
|
userId: CharSequence,
|
||||||
subpacketsCallback: SelfSignatureSubpackets.Callback = SelfSignatureSubpackets.nop()
|
subpacketsCallback: SelfSignatureSubpackets.Callback = SelfSignatureSubpackets.nop()
|
||||||
) = apply {
|
) = apply {
|
||||||
|
val hasPrimaryUID =
|
||||||
|
primaryKey.key.publicKey.userIDs.asSequence().any { uid ->
|
||||||
|
primaryKey.key.publicKey.getSignaturesForID(uid).asSequence().any {
|
||||||
|
it.hashedSubPackets.isPrimaryUserID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val setPrimaryUID =
|
||||||
|
SelfSignatureSubpackets.applyHashed {
|
||||||
|
if (hasPrimaryUID) {
|
||||||
|
setPrimaryUserId(null)
|
||||||
|
} else {
|
||||||
|
setPrimaryUserId()
|
||||||
|
}
|
||||||
|
}
|
||||||
primaryKey.userId(
|
primaryKey.userId(
|
||||||
userId, subpacketsCallback = preferencesCallback.then(subpacketsCallback))
|
userId,
|
||||||
|
subpacketsCallback =
|
||||||
|
preferencesCallback.then(setPrimaryUID).then(subpacketsCallback))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue