mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 04:17:59 +01:00
Increase readability
This commit is contained in:
parent
13f9702b9b
commit
95bd9532bd
1 changed files with 33 additions and 9 deletions
|
@ -962,22 +962,46 @@ internal constructor(primaryKey: PGPKeyPair, subkey: PGPKeyPair, builder: Define
|
||||||
): PGPKeyPair {
|
): PGPKeyPair {
|
||||||
val sigBuilder = SubkeyBindingSignatureBuilder(primaryKey, hashAlgorithm)
|
val sigBuilder = SubkeyBindingSignatureBuilder(primaryKey, hashAlgorithm)
|
||||||
sigBuilder.applyCallback(
|
sigBuilder.applyCallback(
|
||||||
|
// sets key flags
|
||||||
subpacketsCallback
|
subpacketsCallback
|
||||||
.then(SelfSignatureSubpackets.applyHashed { setSignatureCreationTime(bindingTime) })
|
.then(setCreationTime(bindingTime))
|
||||||
.then(
|
// adds back sig if key flags contain sign or certify
|
||||||
SelfSignatureSubpackets.applyHashed {
|
.then(addBackSignatureIfNecessary(hashAlgorithm)))
|
||||||
if (isSigningCapable(getKeyFlags())) {
|
|
||||||
addEmbeddedSignature(
|
|
||||||
PrimaryKeyBindingSignatureBuilder(subkey, hashAlgorithm)
|
|
||||||
.build(primaryKey))
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
val sig = sigBuilder.build(subkey)
|
val sig = sigBuilder.build(subkey)
|
||||||
|
|
||||||
subkey = subkey.plusCertification(sig)
|
subkey = subkey.plusCertification(sig)
|
||||||
return subkey
|
return subkey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a [SelfSignatureSubpackets.Callback] that sets the signature creation time to the
|
||||||
|
* given [bindingTime].
|
||||||
|
*
|
||||||
|
* @param bindingTime signature creation time
|
||||||
|
* @return callback
|
||||||
|
*/
|
||||||
|
private fun setCreationTime(bindingTime: Date): SelfSignatureSubpackets.Callback {
|
||||||
|
return SelfSignatureSubpackets.applyHashed { setSignatureCreationTime(bindingTime) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a [SelfSignatureSubpackets.Callback] that adds a PrimaryKeyBinding Signature
|
||||||
|
* (back-signature) if the subkey is signing capable.
|
||||||
|
*
|
||||||
|
* @param hashAlgorithm hash algorithm to calculate the back-sig with
|
||||||
|
* @return callback
|
||||||
|
*/
|
||||||
|
private fun addBackSignatureIfNecessary(
|
||||||
|
hashAlgorithm: HashAlgorithm
|
||||||
|
): SelfSignatureSubpackets.Callback {
|
||||||
|
return SelfSignatureSubpackets.applyHashed {
|
||||||
|
if (isSigningCapable(getKeyFlags())) {
|
||||||
|
addEmbeddedSignature(
|
||||||
|
PrimaryKeyBindingSignatureBuilder(subkey, hashAlgorithm).build(primaryKey))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return `true` if the given [flags] list contains either [KeyFlag.SIGN_DATA] or
|
* Return `true` if the given [flags] list contains either [KeyFlag.SIGN_DATA] or
|
||||||
* [KeyFlag.CERTIFY_OTHER].
|
* [KeyFlag.CERTIFY_OTHER].
|
||||||
|
|
Loading…
Reference in a new issue