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:
parent
8a48cc40f7
commit
053f6cf362
2 changed files with 6 additions and 20 deletions
|
@ -6,6 +6,7 @@ package org.pgpainless.bouncycastle.extensions
|
|||
|
||||
import java.util.*
|
||||
import openpgp.plusSeconds
|
||||
import org.bouncycastle.bcpg.KeyIdentifier
|
||||
import org.bouncycastle.openpgp.PGPPublicKey
|
||||
import org.bouncycastle.openpgp.PGPSignature
|
||||
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. */
|
||||
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.
|
||||
*
|
||||
* @param fingerprint fingerprint bytes
|
||||
* @param key key
|
||||
*/
|
||||
@Deprecated("Discouraged in favor of method taking an OpenPgpFingerprint.")
|
||||
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(key.keyIdentifier)
|
||||
|
||||
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. */
|
||||
val PGPSignature.isHardRevocation
|
||||
|
|
|
@ -214,15 +214,6 @@ class SignatureUtils {
|
|||
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
|
||||
@Deprecated(
|
||||
"Deprecated in favor of PGPSignature extension method",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue