1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-05 03:55:58 +01:00

Increase readability

This commit is contained in:
Paul Schaub 2024-02-21 14:32:58 +01:00
parent 13f9702b9b
commit 95bd9532bd
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -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].