1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-25 12:27:58 +01:00

AbstractSignatureBuilder: Catch incapable keys early

This commit is contained in:
Paul Schaub 2024-02-22 13:58:37 +01:00
parent 3f518eb1e0
commit 61c6c2116a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -14,6 +14,7 @@ import org.bouncycastle.openpgp.PGPSignature
import org.bouncycastle.openpgp.PGPSignatureGenerator import org.bouncycastle.openpgp.PGPSignatureGenerator
import org.pgpainless.PGPainless import org.pgpainless.PGPainless
import org.pgpainless.algorithm.HashAlgorithm import org.pgpainless.algorithm.HashAlgorithm
import org.pgpainless.algorithm.PublicKeyAlgorithm
import org.pgpainless.algorithm.SignatureType import org.pgpainless.algorithm.SignatureType
import org.pgpainless.algorithm.negotiation.HashAlgorithmNegotiator import org.pgpainless.algorithm.negotiation.HashAlgorithmNegotiator
import org.pgpainless.implementation.ImplementationFactory import org.pgpainless.implementation.ImplementationFactory
@ -35,6 +36,9 @@ abstract class AbstractSignatureBuilder<B : AbstractSignatureBuilder<B>>(
protected abstract val signatureTypePredicate: Predicate<SignatureType> protected abstract val signatureTypePredicate: Predicate<SignatureType>
init { init {
val algorithm =
PublicKeyAlgorithm.requireFromId(privateSigningKey.publicKeyPacket.algorithm)
require(algorithm.isSigningCapable()) { "Key is not signing capable: $algorithm" }
require(signatureTypePredicate.test(_signatureType)) { "Invalid signature type." } require(signatureTypePredicate.test(_signatureType)) { "Invalid signature type." }
} }