mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 04:17:59 +01:00
Improve readability of primaryUserId adjustment
This commit is contained in:
parent
2f7266d771
commit
9785582bd2
2 changed files with 23 additions and 17 deletions
|
@ -147,24 +147,28 @@ open class GenerateOpenPgpKey(
|
|||
userId: CharSequence,
|
||||
subpacketsCallback: SelfSignatureSubpackets.Callback = SelfSignatureSubpackets.nop()
|
||||
) = apply {
|
||||
val hasPrimaryUID =
|
||||
primaryKey.pair.publicKey.userIDs.asSequence().any { uid ->
|
||||
primaryKey.pair.publicKey.getSignaturesForID(uid).asSequence().any {
|
||||
it.hashedSubPackets.isPrimaryUserID
|
||||
primaryKey.userId(
|
||||
userId,
|
||||
subpacketsCallback =
|
||||
preferencesCallback.then(adjustPrimaryUserId()).then(subpacketsCallback))
|
||||
}
|
||||
}
|
||||
val setPrimaryUID =
|
||||
|
||||
private fun adjustPrimaryUserId() =
|
||||
SelfSignatureSubpackets.applyHashed {
|
||||
if (hasPrimaryUID) {
|
||||
if (primaryKeyHasPrimaryUserId()) {
|
||||
setPrimaryUserId(null)
|
||||
} else {
|
||||
setPrimaryUserId()
|
||||
}
|
||||
}
|
||||
primaryKey.userId(
|
||||
userId,
|
||||
subpacketsCallback =
|
||||
preferencesCallback.then(setPrimaryUID).then(subpacketsCallback))
|
||||
|
||||
private fun primaryKeyHasPrimaryUserId() =
|
||||
primaryKey.pair.publicKey.let { pk ->
|
||||
pk.userIDs.asSequence().any { uid ->
|
||||
pk.getSignaturesForID(uid).asSequence().any {
|
||||
it.hashedSubPackets.isPrimaryUserID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -302,7 +306,8 @@ open class GenerateOpenPgpKey(
|
|||
|
||||
return PGPSecretKeyRing(
|
||||
mutableListOf(
|
||||
toSecretKey(primaryKey, true, protector.getEncryptor(primaryKey.pair.keyID)))
|
||||
toSecretKey(
|
||||
primaryKey, true, protector.getEncryptor(primaryKey.pair.keyID)))
|
||||
.plus(
|
||||
subkeys.map {
|
||||
toSecretKey(it, false, protector.getEncryptor(it.pair.keyID))
|
||||
|
|
|
@ -215,7 +215,8 @@ class OpenPgpComponentKeyBuilder {
|
|||
|
||||
// Create back-sig
|
||||
val backSigBuilder =
|
||||
PrimaryKeyBindingSignatureBuilder(pair.privateKey, pair.publicKey, hashAlgorithm)
|
||||
PrimaryKeyBindingSignatureBuilder(
|
||||
pair.privateKey, pair.publicKey, hashAlgorithm)
|
||||
|
||||
backSigBuilder.hashedSubpackets.setSignatureCreationTime(bindingTime)
|
||||
|
||||
|
|
Loading…
Reference in a new issue