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

PGPSignatureExtensions: Port wasIssuedBy() to KeyIdentifier

This commit is contained in:
Paul Schaub 2025-03-20 18:51:29 +01:00
parent 8a48cc40f7
commit 053f6cf362
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 6 additions and 20 deletions

View file

@ -6,6 +6,7 @@ package org.pgpainless.bouncycastle.extensions
import java.util.* import java.util.*
import openpgp.plusSeconds import openpgp.plusSeconds
import org.bouncycastle.bcpg.KeyIdentifier
import org.bouncycastle.openpgp.PGPPublicKey import org.bouncycastle.openpgp.PGPPublicKey
import org.bouncycastle.openpgp.PGPSignature import org.bouncycastle.openpgp.PGPSignature
import org.pgpainless.algorithm.HashAlgorithm import org.pgpainless.algorithm.HashAlgorithm
@ -56,23 +57,17 @@ val PGPSignature.issuerKeyId: Long
/** Return true, if the signature was likely issued by a key with the given fingerprint. */ /** Return true, if the signature was likely issued by a key with the given fingerprint. */
fun PGPSignature.wasIssuedBy(fingerprint: OpenPgpFingerprint): Boolean = fun PGPSignature.wasIssuedBy(fingerprint: OpenPgpFingerprint): Boolean =
this.fingerprint?.let { it.keyId == fingerprint.keyId } ?: (keyID == fingerprint.keyId) wasIssuedBy(fingerprint.keyIdentifier)
/** /**
* Return true, if the signature was likely issued by a key with the given fingerprint. * Return true, if the signature was likely issued by a key with the given fingerprint.
* *
* @param fingerprint fingerprint bytes * @param key key
*/ */
@Deprecated("Discouraged in favor of method taking an OpenPgpFingerprint.") fun PGPSignature.wasIssuedBy(key: PGPPublicKey): Boolean = wasIssuedBy(key.keyIdentifier)
fun PGPSignature.wasIssuedBy(fingerprint: ByteArray): Boolean =
try {
wasIssuedBy(OpenPgpFingerprint.parseFromBinary(fingerprint))
} catch (e: IllegalArgumentException) {
// Unknown fingerprint length / format
false
}
fun PGPSignature.wasIssuedBy(key: PGPPublicKey): Boolean = wasIssuedBy(OpenPgpFingerprint.of(key)) fun PGPSignature.wasIssuedBy(keyIdentifier: KeyIdentifier): Boolean =
KeyIdentifier.matches(this.keyIdentifiers, keyIdentifier, true)
/** Return true, if this signature is a hard revocation. */ /** Return true, if this signature is a hard revocation. */
val PGPSignature.isHardRevocation val PGPSignature.isHardRevocation

View file

@ -214,15 +214,6 @@ class SignatureUtils {
return Hex.toHexString(signature.digestPrefix) return Hex.toHexString(signature.digestPrefix)
} }
@JvmStatic
@Deprecated(
"Deprecated in favor of PGPSignature extension method",
ReplaceWith(
"signature.wasIssuedBy(fingerprint)", "org.bouncycastle.extensions.wasIssuedBy"))
fun wasIssuedBy(fingerprint: ByteArray, signature: PGPSignature): Boolean {
return signature.wasIssuedBy(fingerprint)
}
@JvmStatic @JvmStatic
@Deprecated( @Deprecated(
"Deprecated in favor of PGPSignature extension method", "Deprecated in favor of PGPSignature extension method",