From 61c6c2116af0ea7943e6f885819fbdc9aa645305 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 22 Feb 2024 13:58:37 +0100 Subject: [PATCH] AbstractSignatureBuilder: Catch incapable keys early --- .../pgpainless/signature/builder/AbstractSignatureBuilder.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/signature/builder/AbstractSignatureBuilder.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/signature/builder/AbstractSignatureBuilder.kt index eb4c9f1f..26b50a6d 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/signature/builder/AbstractSignatureBuilder.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/signature/builder/AbstractSignatureBuilder.kt @@ -14,6 +14,7 @@ import org.bouncycastle.openpgp.PGPSignature import org.bouncycastle.openpgp.PGPSignatureGenerator import org.pgpainless.PGPainless import org.pgpainless.algorithm.HashAlgorithm +import org.pgpainless.algorithm.PublicKeyAlgorithm import org.pgpainless.algorithm.SignatureType import org.pgpainless.algorithm.negotiation.HashAlgorithmNegotiator import org.pgpainless.implementation.ImplementationFactory @@ -35,6 +36,9 @@ abstract class AbstractSignatureBuilder>( protected abstract val signatureTypePredicate: Predicate init { + val algorithm = + PublicKeyAlgorithm.requireFromId(privateSigningKey.publicKeyPacket.algorithm) + require(algorithm.isSigningCapable()) { "Key is not signing capable: $algorithm" } require(signatureTypePredicate.test(_signatureType)) { "Invalid signature type." } }