1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-09 18:29:39 +02:00

SOP certify-userid: Properly throw KeyCannotCertify exception

This commit is contained in:
Paul Schaub 2025-04-10 15:26:59 +02:00
parent d540febc7f
commit b7dedbd619
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -9,6 +9,7 @@ import java.io.OutputStream
import org.bouncycastle.bcpg.PacketFormat import org.bouncycastle.bcpg.PacketFormat
import org.bouncycastle.openpgp.api.OpenPGPKey import org.bouncycastle.openpgp.api.OpenPGPKey
import org.pgpainless.PGPainless import org.pgpainless.PGPainless
import org.pgpainless.exception.KeyException
import org.pgpainless.util.ArmoredOutputStreamFactory import org.pgpainless.util.ArmoredOutputStreamFactory
import org.pgpainless.util.Passphrase import org.pgpainless.util.Passphrase
import sop.Ready import sop.Ready
@ -45,12 +46,16 @@ class CertifyUserIdImpl(private val api: PGPainless) : CertifyUserId {
var certificate = cert var certificate = cert
keys.forEach { key -> keys.forEach { key ->
userIds.forEach { userId -> userIds.forEach { userId ->
certificate = try {
api.generateCertification() certificate =
.certifyUserId(userId, certificate) api.generateCertification()
.withKey(key, protector) .certifyUserId(userId, certificate)
.build() .withKey(key, protector)
.certifiedCertificate .build()
.certifiedCertificate
} catch (e: KeyException) {
throw SOPGPException.KeyCannotCertify(e)
}
} }
} }