mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 20:37:59 +01:00
Fix method hierarchy of addBindingSignature()
This commit is contained in:
parent
7f07503064
commit
13f9702b9b
1 changed files with 26 additions and 44 deletions
|
@ -12,7 +12,6 @@ import org.bouncycastle.extensions.plusCertification
|
||||||
import org.bouncycastle.openpgp.PGPKeyPair
|
import org.bouncycastle.openpgp.PGPKeyPair
|
||||||
import org.bouncycastle.openpgp.PGPSecretKey
|
import org.bouncycastle.openpgp.PGPSecretKey
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
||||||
import org.bouncycastle.openpgp.PGPSignature
|
|
||||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector
|
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector
|
||||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator
|
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator
|
||||||
import org.bouncycastle.util.io.Streams
|
import org.bouncycastle.util.io.Streams
|
||||||
|
@ -926,11 +925,22 @@ internal constructor(
|
||||||
* @param bindingTime creation time of the binding signature
|
* @param bindingTime creation time of the binding signature
|
||||||
* @return modified subkey pair
|
* @return modified subkey pair
|
||||||
*/
|
*/
|
||||||
abstract fun addBindingSignature(
|
fun addBindingSignature(
|
||||||
subpacketsCallback: SelfSignatureSubpackets.Callback = SelfSignatureSubpackets.nop(),
|
subpacketsCallback: SelfSignatureSubpackets.Callback = SelfSignatureSubpackets.nop(),
|
||||||
hashAlgorithm: HashAlgorithm =
|
hashAlgorithm: HashAlgorithm =
|
||||||
builder.policy.certificationSignatureHashAlgorithmPolicy.defaultHashAlgorithm,
|
builder.policy.certificationSignatureHashAlgorithmPolicy.defaultHashAlgorithm,
|
||||||
bindingTime: Date = subkey.publicKey.creationTime
|
bindingTime: Date = subkey.publicKey.creationTime
|
||||||
|
): PGPKeyPair {
|
||||||
|
builder.sanitizeHashAlgorithm(hashAlgorithm)
|
||||||
|
builder.sanitizeBindingTime(bindingTime, subkey)
|
||||||
|
|
||||||
|
return doAddBindingSignature(subpacketsCallback, hashAlgorithm, bindingTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun doAddBindingSignature(
|
||||||
|
subpacketsCallback: SelfSignatureSubpackets.Callback,
|
||||||
|
hashAlgorithm: HashAlgorithm,
|
||||||
|
bindingTime: Date
|
||||||
): PGPKeyPair
|
): PGPKeyPair
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -945,46 +955,15 @@ class ApplyToSubkeyV4
|
||||||
internal constructor(primaryKey: PGPKeyPair, subkey: PGPKeyPair, builder: DefineSubkeys<*>) :
|
internal constructor(primaryKey: PGPKeyPair, subkey: PGPKeyPair, builder: DefineSubkeys<*>) :
|
||||||
ApplyToSubkey(primaryKey, subkey, builder) {
|
ApplyToSubkey(primaryKey, subkey, builder) {
|
||||||
|
|
||||||
override fun addBindingSignature(
|
override fun doAddBindingSignature(
|
||||||
subpacketsCallback: SelfSignatureSubpackets.Callback,
|
subpacketsCallback: SelfSignatureSubpackets.Callback,
|
||||||
hashAlgorithm: HashAlgorithm,
|
hashAlgorithm: HashAlgorithm,
|
||||||
bindingTime: Date
|
bindingTime: Date
|
||||||
): PGPKeyPair {
|
): PGPKeyPair {
|
||||||
builder.sanitizeHashAlgorithm(hashAlgorithm)
|
val sigBuilder = SubkeyBindingSignatureBuilder(primaryKey, hashAlgorithm)
|
||||||
builder.sanitizeBindingTime(bindingTime, subkey)
|
sigBuilder.applyCallback(
|
||||||
|
|
||||||
val sig =
|
|
||||||
buildBindingSignature(
|
|
||||||
primaryKey, subkey, hashAlgorithm, bindingTime, subpacketsCallback)
|
|
||||||
|
|
||||||
subkey = subkey.plusCertification(sig)
|
|
||||||
return subkey
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a version 4 binding signature that binds the [subkey] to the [primaryKey].
|
|
||||||
*
|
|
||||||
* @param primaryKey primary key pair
|
|
||||||
* @param subkey subkey pair
|
|
||||||
* @param hashAlgorithm hash algorithm to be used during signature calculation
|
|
||||||
* @param bindingTime creation time of the subkey
|
|
||||||
* @param subpacketsCallback callback to modify the subpackets of the binding signature
|
|
||||||
* @return subkey binding signature
|
|
||||||
*/
|
|
||||||
private fun buildBindingSignature(
|
|
||||||
primaryKey: PGPKeyPair,
|
|
||||||
subkey: PGPKeyPair,
|
|
||||||
hashAlgorithm: HashAlgorithm,
|
|
||||||
bindingTime: Date,
|
|
||||||
subpacketsCallback: SelfSignatureSubpackets.Callback
|
|
||||||
): PGPSignature {
|
|
||||||
return SubkeyBindingSignatureBuilder(primaryKey, hashAlgorithm)
|
|
||||||
.applyCallback(
|
|
||||||
subpacketsCallback
|
subpacketsCallback
|
||||||
.then(
|
.then(SelfSignatureSubpackets.applyHashed { setSignatureCreationTime(bindingTime) })
|
||||||
SelfSignatureSubpackets.applyHashed {
|
|
||||||
setSignatureCreationTime(bindingTime)
|
|
||||||
})
|
|
||||||
.then(
|
.then(
|
||||||
SelfSignatureSubpackets.applyHashed {
|
SelfSignatureSubpackets.applyHashed {
|
||||||
if (isSigningCapable(getKeyFlags())) {
|
if (isSigningCapable(getKeyFlags())) {
|
||||||
|
@ -993,7 +972,10 @@ internal constructor(primaryKey: PGPKeyPair, subkey: PGPKeyPair, builder: Define
|
||||||
.build(primaryKey))
|
.build(primaryKey))
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.build(subkey)
|
val sig = sigBuilder.build(subkey)
|
||||||
|
|
||||||
|
subkey = subkey.plusCertification(sig)
|
||||||
|
return subkey
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue