1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-14 00:12:06 +01:00

Replace usage of KeyIdUtil.formatKeyId() in Kotlin classes with Long.hexKeyId()

This commit is contained in:
Paul Schaub 2023-09-04 14:37:18 +02:00
parent fc97215f80
commit 649fdcf810
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
5 changed files with 19 additions and 19 deletions

View file

@ -4,6 +4,7 @@
package org.pgpainless.decryption_verification
import _kotlin.hexKeyId
import org.bouncycastle.bcpg.BCPGInputStream
import org.bouncycastle.bcpg.UnsupportedPacketVersionException
import org.bouncycastle.openpgp.*
@ -21,7 +22,6 @@ import org.pgpainless.exception.*
import org.pgpainless.implementation.ImplementationFactory
import org.pgpainless.key.SubkeyIdentifier
import org.pgpainless.key.protection.UnlockSecretKey
import org.pgpainless.key.util.KeyIdUtil
import org.pgpainless.key.util.KeyRingUtils
import org.pgpainless.policy.Policy
import org.pgpainless.signature.SignatureUtils
@ -180,7 +180,7 @@ class OpenPgpMessageInputStream(
private fun processOnePassSignature() {
syntaxVerifier.next(InputSymbol.ONE_PASS_SIGNATURE)
val ops = packetInputStream!!.readOnePassSignature()
LOGGER.debug("One-Pass-Signature Packet by key ${KeyIdUtil.formatKeyId(ops.keyID)} at depth ${layerMetadata.depth} encountered.")
LOGGER.debug("One-Pass-Signature Packet by key ${ops.keyID.hexKeyId()} at depth ${layerMetadata.depth} encountered.")
signatures.addOnePassSignature(ops)
}
@ -197,11 +197,11 @@ class OpenPgpMessageInputStream(
val keyId = SignatureUtils.determineIssuerKeyId(signature)
if (isSigForOps) {
LOGGER.debug("Signature Packet corresponding to One-Pass-Signature by key ${KeyIdUtil.formatKeyId(keyId)} at depth ${layerMetadata.depth} encountered.")
LOGGER.debug("Signature Packet corresponding to One-Pass-Signature by key ${keyId.hexKeyId()} at depth ${layerMetadata.depth} encountered.")
signatures.leaveNesting() // TODO: Only leave nesting if all OPSs of the nesting layer are dealt with
signatures.addCorrespondingOnePassSignature(signature, layerMetadata, policy)
} else {
LOGGER.debug("Prepended Signature Packet by key ${KeyIdUtil.formatKeyId(keyId)} at depth ${layerMetadata.depth} encountered.")
LOGGER.debug("Prepended Signature Packet by key ${keyId.hexKeyId()} at depth ${layerMetadata.depth} encountered.")
signatures.addPrependedSignature(signature)
}
}
@ -282,10 +282,10 @@ class OpenPgpMessageInputStream(
// try (known) secret keys
for (pkesk in esks.pkesks) {
val keyId = pkesk.keyID
LOGGER.debug("Encountered PKESK for recipient ${KeyIdUtil.formatKeyId(keyId)}")
LOGGER.debug("Encountered PKESK for recipient ${keyId.hexKeyId()}")
val decryptionKeys = getDecryptionKey(keyId)
if (decryptionKeys == null) {
LOGGER.debug("Skipping PKESK because no matching key ${KeyIdUtil.formatKeyId(keyId)} was provided.")
LOGGER.debug("Skipping PKESK because no matching key ${keyId.hexKeyId()} was provided.")
continue
}
val secretKey = decryptionKeys.getSecretKey(keyId)
@ -618,7 +618,7 @@ class OpenPgpMessageInputStream(
if (check != null) {
detachedSignatures.add(check)
} else {
LOGGER.debug("No suitable certificate for verification of signature by key ${KeyIdUtil.formatKeyId(keyId)} found.")
LOGGER.debug("No suitable certificate for verification of signature by key ${keyId.hexKeyId()} found.")
detachedSignaturesWithMissingCert.add(SignatureVerification.Failure(
SignatureVerification(signature, null),
SignatureValidationException("Missing verification key.")))
@ -631,7 +631,7 @@ class OpenPgpMessageInputStream(
if (check != null) {
prependedSignatures.add(check)
} else {
LOGGER.debug("No suitable certificate for verification of signature by key ${KeyIdUtil.formatKeyId(keyId)} found.")
LOGGER.debug("No suitable certificate for verification of signature by key ${keyId.hexKeyId()} found.")
prependedSignaturesWithMissingCert.add(SignatureVerification.Failure(
SignatureVerification(signature, null),
SignatureValidationException("Missing verification key")
@ -693,7 +693,7 @@ class OpenPgpMessageInputStream(
}
if (!found) {
LOGGER.debug("No suitable certificate for verification of signature by key ${KeyIdUtil.formatKeyId(keyId)} found.")
LOGGER.debug("No suitable certificate for verification of signature by key ${keyId.hexKeyId()} found.")
inbandSignaturesWithMissingCert.add(SignatureVerification.Failure(
SignatureVerification(signature, null),
SignatureValidationException("Missing verification key.")

View file

@ -4,9 +4,9 @@
package org.pgpainless.key
import _kotlin.hexKeyId
import org.bouncycastle.openpgp.PGPKeyRing
import org.bouncycastle.openpgp.PGPPublicKey
import org.pgpainless.key.util.KeyIdUtil
/**
* Tuple class used to identify a subkey by fingerprints of the primary key of the subkeys key ring,
@ -22,7 +22,7 @@ class SubkeyIdentifier(
constructor(keys: PGPKeyRing, keyId: Long): this(
OpenPgpFingerprint.of(keys.publicKey),
OpenPgpFingerprint.of(keys.getPublicKey(keyId) ?:
throw NoSuchElementException("OpenPGP key does not contain subkey ${KeyIdUtil.formatKeyId(keyId)}")))
throw NoSuchElementException("OpenPGP key does not contain subkey ${keyId.hexKeyId()}")))
constructor(keys: PGPKeyRing, subkeyFingerprint: OpenPgpFingerprint): this(OpenPgpFingerprint.of(keys), subkeyFingerprint)
val keyId = subkeyFingerprint.keyId
@ -42,7 +42,7 @@ class SubkeyIdentifier(
return false
}
return primaryKeyFingerprint.equals(other.primaryKeyFingerprint) && subkeyFingerprint.equals(other.subkeyFingerprint)
return primaryKeyFingerprint == other.primaryKeyFingerprint && subkeyFingerprint == other.subkeyFingerprint
}
override fun hashCode(): Int {

View file

@ -4,11 +4,11 @@
package org.pgpainless.key.protection
import _kotlin.hexKeyId
import org.bouncycastle.openpgp.PGPKeyRing
import org.bouncycastle.openpgp.PGPPublicKey
import org.pgpainless.key.OpenPgpFingerprint
import org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider
import org.pgpainless.key.util.KeyIdUtil
import org.pgpainless.util.Passphrase
/**
@ -54,7 +54,7 @@ class CachingSecretKeyRingProtector : SecretKeyRingProtector, SecretKeyPassphras
*/
fun addPassphrase(keyId: Long, passphrase: Passphrase) = apply {
require(!cache.containsKey(keyId)) {
"The cache already holds a passphrase for ID ${KeyIdUtil.formatKeyId(keyId)}.\n" +
"The cache already holds a passphrase for ID ${keyId.hexKeyId()}.\n" +
"If you want to replace this passphrase, use replacePassphrase(Long, Passphrase) instead."
}
cache[keyId] = passphrase
@ -90,7 +90,7 @@ class CachingSecretKeyRingProtector : SecretKeyRingProtector, SecretKeyPassphras
// check for existing passphrases before doing anything
keyRing.publicKeys.forEach {
require(!cache.containsKey(it.keyID)) {
"The cache already holds a passphrase for the key with ID ${KeyIdUtil.formatKeyId(it.keyID)}.\n" +
"The cache already holds a passphrase for the key with ID ${it.keyID.hexKeyId()}.\n" +
"If you want to replace the passphrase, use replacePassphrase(PGPKeyRing, Passphrase) instead."
}
}

View file

@ -5,6 +5,7 @@
package org.pgpainless.key.protection
import _kotlin.hexKeyId
import org.bouncycastle.openpgp.PGPException
import org.bouncycastle.openpgp.PGPPrivateKey
import org.bouncycastle.openpgp.PGPSecretKey
@ -13,7 +14,6 @@ import org.pgpainless.PGPainless
import org.pgpainless.exception.KeyIntegrityException
import org.pgpainless.exception.WrongPassphraseException
import org.pgpainless.key.info.KeyInfo
import org.pgpainless.key.util.KeyIdUtil
import org.pgpainless.key.util.PublicKeyParameterValidationUtil
import org.pgpainless.util.Passphrase
import kotlin.jvm.Throws
@ -43,7 +43,7 @@ class UnlockSecretKey {
if (privateKey == null) {
if (secretKey.s2K.type in 100..110) {
throw PGPException("Cannot decrypt secret key ${KeyIdUtil.formatKeyId(secretKey.keyID)}: \n" +
throw PGPException("Cannot decrypt secret key ${secretKey.keyID.hexKeyId()}: \n" +
"Unsupported private S2K type ${secretKey.s2K.type}")
}
throw PGPException("Cannot decrypt secret key.")

View file

@ -4,6 +4,7 @@
package org.pgpainless.signature.subpackets
import _kotlin.hexKeyId
import org.bouncycastle.bcpg.sig.*
import org.bouncycastle.openpgp.PGPPublicKey
import org.bouncycastle.openpgp.PGPSignature
@ -17,7 +18,6 @@ import org.pgpainless.key.OpenPgpV4Fingerprint
import org.pgpainless.key.OpenPgpV5Fingerprint
import org.pgpainless.key.OpenPgpV6Fingerprint
import org.pgpainless.key.generation.type.KeyType
import org.pgpainless.key.util.KeyIdUtil
import org.pgpainless.signature.SignatureUtils
import java.util.*
@ -143,7 +143,7 @@ class SignatureSubpacketsUtil {
@JvmStatic
fun getKeyExpirationTimeAsDate(signature: PGPSignature, signingKey: PGPPublicKey): Date? =
require(signature.keyID == signingKey.keyID) {
"Provided key (${KeyIdUtil.formatKeyId(signingKey.keyID)}) did not create the signature (${KeyIdUtil.formatKeyId(signature.keyID)})"
"Provided key (${signingKey.keyID.hexKeyId()}) did not create the signature (${signature.keyID.hexKeyId()})"
}.run {
getKeyExpirationTime(signature)?.let {
SignatureUtils.datePlusSeconds(signingKey.creationTime, it.time)