mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 12:27:58 +01:00
Add PGPKeyPair.plusCertification() methods
This commit is contained in:
parent
787d2987f0
commit
177249dd53
2 changed files with 22 additions and 17 deletions
|
@ -9,6 +9,8 @@ import org.bouncycastle.bcpg.PublicSubkeyPacket
|
||||||
import org.bouncycastle.openpgp.PGPKeyPair
|
import org.bouncycastle.openpgp.PGPKeyPair
|
||||||
import org.bouncycastle.openpgp.PGPPrivateKey
|
import org.bouncycastle.openpgp.PGPPrivateKey
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey
|
import org.bouncycastle.openpgp.PGPPublicKey
|
||||||
|
import org.bouncycastle.openpgp.PGPSignature
|
||||||
|
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector
|
||||||
import org.pgpainless.implementation.ImplementationFactory
|
import org.pgpainless.implementation.ImplementationFactory
|
||||||
|
|
||||||
fun PGPKeyPair.toPrimaryKeyFormat(): PGPKeyPair {
|
fun PGPKeyPair.toPrimaryKeyFormat(): PGPKeyPair {
|
||||||
|
@ -30,3 +32,16 @@ fun PGPKeyPair.toSubkeyFormat(): PGPKeyPair {
|
||||||
PGPPublicKey(subkey, fpCalc),
|
PGPPublicKey(subkey, fpCalc),
|
||||||
PGPPrivateKey(publicKey.keyID, subkey, privateKey.privateKeyDataPacket))
|
PGPPrivateKey(publicKey.keyID, subkey, privateKey.privateKeyDataPacket))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun PGPKeyPair.plusCertification(userId: CharSequence, certification: PGPSignature): PGPKeyPair =
|
||||||
|
PGPKeyPair(
|
||||||
|
PGPPublicKey.addCertification(publicKey, userId.toString(), certification), privateKey)
|
||||||
|
|
||||||
|
fun PGPKeyPair.plusCertification(
|
||||||
|
userAttribute: PGPUserAttributeSubpacketVector,
|
||||||
|
certification: PGPSignature
|
||||||
|
): PGPKeyPair =
|
||||||
|
PGPKeyPair(PGPPublicKey.addCertification(publicKey, userAttribute, certification), privateKey)
|
||||||
|
|
||||||
|
fun PGPKeyPair.plusCertification(certification: PGPSignature): PGPKeyPair =
|
||||||
|
PGPKeyPair(PGPPublicKey.addCertification(publicKey, certification), privateKey)
|
||||||
|
|
|
@ -3,8 +3,8 @@ package org.pgpainless.key.generation
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import org.bouncycastle.bcpg.attr.ImageAttribute
|
import org.bouncycastle.bcpg.attr.ImageAttribute
|
||||||
|
import org.bouncycastle.extensions.plusCertification
|
||||||
import org.bouncycastle.openpgp.PGPKeyPair
|
import org.bouncycastle.openpgp.PGPKeyPair
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey
|
|
||||||
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.PGPSignature
|
||||||
|
@ -535,10 +535,7 @@ abstract class ApplyToPrimaryKey(var keyPair: PGPKeyPair, val builder: DefinePri
|
||||||
hashAlgorithm,
|
hashAlgorithm,
|
||||||
subpacketsCallback)
|
subpacketsCallback)
|
||||||
|
|
||||||
keyPair =
|
keyPair = keyPair.plusCertification(userId, sig)
|
||||||
PGPKeyPair(
|
|
||||||
PGPPublicKey.addCertification(keyPair.publicKey, userId.toString(), sig),
|
|
||||||
keyPair.privateKey)
|
|
||||||
return keyPair
|
return keyPair
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,11 +555,7 @@ abstract class ApplyToPrimaryKey(var keyPair: PGPKeyPair, val builder: DefinePri
|
||||||
hashAlgorithm,
|
hashAlgorithm,
|
||||||
subpacketsCallback)
|
subpacketsCallback)
|
||||||
|
|
||||||
keyPair =
|
keyPair = keyPair.plusCertification(userAttribute, sig)
|
||||||
PGPKeyPair(
|
|
||||||
PGPPublicKey.addCertification(keyPair.publicKey, userAttribute, sig),
|
|
||||||
keyPair.privateKey)
|
|
||||||
|
|
||||||
return keyPair
|
return keyPair
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,9 +572,7 @@ abstract class ApplyToPrimaryKey(var keyPair: PGPKeyPair, val builder: DefinePri
|
||||||
SelfSignatureSubpackets.applyHashed {
|
SelfSignatureSubpackets.applyHashed {
|
||||||
setSignatureCreationTime(bindingTime)
|
setSignatureCreationTime(bindingTime)
|
||||||
}))
|
}))
|
||||||
keyPair =
|
keyPair = keyPair.plusCertification(sig)
|
||||||
PGPKeyPair(
|
|
||||||
PGPPublicKey.addCertification(keyPair.publicKey, sig), keyPair.privateKey)
|
|
||||||
return keyPair
|
return keyPair
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -680,7 +671,7 @@ abstract class ApplyToPrimaryKey(var keyPair: PGPKeyPair, val builder: DefinePri
|
||||||
*/
|
*/
|
||||||
abstract class ApplyToSubkey(
|
abstract class ApplyToSubkey(
|
||||||
val primaryKey: PGPKeyPair,
|
val primaryKey: PGPKeyPair,
|
||||||
val subkey: PGPKeyPair,
|
var subkey: PGPKeyPair,
|
||||||
val builder: DefineSubkeys<*>
|
val builder: DefineSubkeys<*>
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -718,8 +709,8 @@ abstract class ApplyToSubkey(
|
||||||
buildBindingSignature(
|
buildBindingSignature(
|
||||||
primaryKey, subkey, hashAlgorithm, bindingTime, subpacketsCallback)
|
primaryKey, subkey, hashAlgorithm, bindingTime, subpacketsCallback)
|
||||||
|
|
||||||
return PGPKeyPair(
|
subkey = subkey.plusCertification(sig)
|
||||||
PGPPublicKey.addCertification(subkey.publicKey, sig), subkey.privateKey)
|
return subkey
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -890,7 +881,6 @@ class OpenPgpKeyTemplates {
|
||||||
KeyFlag.ENCRYPT_COMMS,
|
KeyFlag.ENCRYPT_COMMS,
|
||||||
KeyFlag.ENCRYPT_STORAGE)
|
KeyFlag.ENCRYPT_STORAGE)
|
||||||
})
|
})
|
||||||
keyPair
|
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue