mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 10:19:39 +02:00
PGPSignatureExtensions: Port wasIssuedBy() to KeyIdentifier
This commit is contained in:
parent
24f871c178
commit
6d25ddefab
2 changed files with 6 additions and 20 deletions
|
@ -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
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue