mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-22 19:08:00 +01:00
Rename heyKeyId -> openPgpKeyId
This commit is contained in:
parent
39e170064c
commit
d8df6c35d0
8 changed files with 32 additions and 32 deletions
|
@ -2,19 +2,19 @@
|
|||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package _kotlin
|
||||
package openpgp
|
||||
|
||||
/**
|
||||
* Format this Long as a 16 digit uppercase hex number.
|
||||
* Format this Long as an OpenPGP key-ID (16 digit uppercase hex number).
|
||||
*/
|
||||
fun Long.hexKeyId(): String {
|
||||
fun Long.openPgpKeyId(): String {
|
||||
return String.format("%016X", this).uppercase()
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a 16 digit hex number into a Long.
|
||||
* Parse a Long form a 16 digit hex encoded OpenPgp key-ID.
|
||||
*/
|
||||
fun Long.Companion.fromHexKeyId(hexKeyId: String): Long {
|
||||
fun Long.Companion.fromOpenPgpKeyId(hexKeyId: String): Long {
|
||||
require("^[0-9A-Fa-f]{16}$".toRegex().matches(hexKeyId)) {
|
||||
"Provided long key-id does not match expected format. " +
|
||||
"A long key-id consists of 16 hexadecimal characters."
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package org.pgpainless.decryption_verification
|
||||
|
||||
import _kotlin.hexKeyId
|
||||
import openpgp.openPgpKeyId
|
||||
import org.bouncycastle.bcpg.BCPGInputStream
|
||||
import org.bouncycastle.bcpg.UnsupportedPacketVersionException
|
||||
import org.bouncycastle.openpgp.*
|
||||
|
@ -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 ${ops.keyID.hexKeyId()} at depth ${layerMetadata.depth} encountered.")
|
||||
LOGGER.debug("One-Pass-Signature Packet by key ${ops.keyID.openPgpKeyId()} 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 ${keyId.hexKeyId()} at depth ${layerMetadata.depth} encountered.")
|
||||
LOGGER.debug("Signature Packet corresponding to One-Pass-Signature by key ${keyId.openPgpKeyId()} 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 ${keyId.hexKeyId()} at depth ${layerMetadata.depth} encountered.")
|
||||
LOGGER.debug("Prepended Signature Packet by key ${keyId.openPgpKeyId()} 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 ${keyId.hexKeyId()}")
|
||||
LOGGER.debug("Encountered PKESK for recipient ${keyId.openPgpKeyId()}")
|
||||
val decryptionKeys = getDecryptionKey(keyId)
|
||||
if (decryptionKeys == null) {
|
||||
LOGGER.debug("Skipping PKESK because no matching key ${keyId.hexKeyId()} was provided.")
|
||||
LOGGER.debug("Skipping PKESK because no matching key ${keyId.openPgpKeyId()} 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 ${keyId.hexKeyId()} found.")
|
||||
LOGGER.debug("No suitable certificate for verification of signature by key ${keyId.openPgpKeyId()} 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 ${keyId.hexKeyId()} found.")
|
||||
LOGGER.debug("No suitable certificate for verification of signature by key ${keyId.openPgpKeyId()} 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 ${keyId.hexKeyId()} found.")
|
||||
LOGGER.debug("No suitable certificate for verification of signature by key ${keyId.openPgpKeyId()} found.")
|
||||
inbandSignaturesWithMissingCert.add(SignatureVerification.Failure(
|
||||
SignatureVerification(signature, null),
|
||||
SignatureValidationException("Missing verification key.")
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package org.pgpainless.key
|
||||
|
||||
import _kotlin.hexKeyId
|
||||
import openpgp.openPgpKeyId
|
||||
import org.bouncycastle.openpgp.PGPKeyRing
|
||||
import org.bouncycastle.openpgp.PGPPublicKey
|
||||
|
||||
|
@ -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 ${keyId.hexKeyId()}")))
|
||||
throw NoSuchElementException("OpenPGP key does not contain subkey ${keyId.openPgpKeyId()}")))
|
||||
constructor(keys: PGPKeyRing, subkeyFingerprint: OpenPgpFingerprint): this(OpenPgpFingerprint.of(keys), subkeyFingerprint)
|
||||
|
||||
val keyId = subkeyFingerprint.keyId
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package org.pgpainless.key.protection
|
||||
|
||||
import _kotlin.hexKeyId
|
||||
import openpgp.openPgpKeyId
|
||||
import org.bouncycastle.openpgp.PGPKeyRing
|
||||
import org.bouncycastle.openpgp.PGPPublicKey
|
||||
import org.pgpainless.key.OpenPgpFingerprint
|
||||
|
@ -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 ${keyId.hexKeyId()}.\n" +
|
||||
"The cache already holds a passphrase for ID ${keyId.openPgpKeyId()}.\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 ${it.keyID.hexKeyId()}.\n" +
|
||||
"The cache already holds a passphrase for the key with ID ${it.keyID.openPgpKeyId()}.\n" +
|
||||
"If you want to replace the passphrase, use replacePassphrase(PGPKeyRing, Passphrase) instead."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
package org.pgpainless.key.protection
|
||||
|
||||
import _kotlin.hexKeyId
|
||||
import openpgp.openPgpKeyId
|
||||
import org.bouncycastle.openpgp.PGPException
|
||||
import org.bouncycastle.openpgp.PGPPrivateKey
|
||||
import org.bouncycastle.openpgp.PGPSecretKey
|
||||
|
@ -43,7 +43,7 @@ class UnlockSecretKey {
|
|||
|
||||
if (privateKey == null) {
|
||||
if (secretKey.s2K.type in 100..110) {
|
||||
throw PGPException("Cannot decrypt secret key ${secretKey.keyID.hexKeyId()}: \n" +
|
||||
throw PGPException("Cannot decrypt secret key ${secretKey.keyID.openPgpKeyId()}: \n" +
|
||||
"Unsupported private S2K type ${secretKey.s2K.type}")
|
||||
}
|
||||
throw PGPException("Cannot decrypt secret key.")
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
package org.pgpainless.key.util
|
||||
|
||||
import _kotlin.fromHexKeyId
|
||||
import _kotlin.hexKeyId
|
||||
import openpgp.fromOpenPgpKeyId
|
||||
import openpgp.openPgpKeyId
|
||||
|
||||
class KeyIdUtil {
|
||||
|
||||
|
@ -21,7 +21,7 @@ class KeyIdUtil {
|
|||
@JvmStatic
|
||||
@Deprecated("Superseded by Long extension method.",
|
||||
ReplaceWith("Long.fromHexKeyId(longKeyId)"))
|
||||
fun fromLongKeyId(longKeyId: String) = Long.fromHexKeyId(longKeyId)
|
||||
fun fromLongKeyId(longKeyId: String) = Long.fromOpenPgpKeyId(longKeyId)
|
||||
|
||||
/**
|
||||
* Format a long key-ID as upper-case hex string.
|
||||
|
@ -31,6 +31,6 @@ class KeyIdUtil {
|
|||
@JvmStatic
|
||||
@Deprecated("Superseded by Long extension method.",
|
||||
ReplaceWith("keyId.hexKeyId()"))
|
||||
fun formatKeyId(keyId: Long) = keyId.hexKeyId()
|
||||
fun formatKeyId(keyId: Long) = keyId.openPgpKeyId()
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package org.pgpainless.key.util
|
||||
|
||||
import _kotlin.hexKeyId
|
||||
import openpgp.openPgpKeyId
|
||||
import org.bouncycastle.bcpg.S2K
|
||||
import org.bouncycastle.bcpg.SecretKeyPacket
|
||||
import org.bouncycastle.extensions.certificate
|
||||
|
@ -100,7 +100,7 @@ class KeyRingUtils {
|
|||
@JvmStatic
|
||||
fun requirePublicKeyFrom(keyRing: PGPKeyRing, subKeyId: Long): PGPPublicKey {
|
||||
return keyRing.getPublicKey(subKeyId)
|
||||
?: throw NoSuchElementException("KeyRing does not contain public key with keyId ${subKeyId.hexKeyId()}.")
|
||||
?: throw NoSuchElementException("KeyRing does not contain public key with keyId ${subKeyId.openPgpKeyId()}.")
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,7 +114,7 @@ class KeyRingUtils {
|
|||
@JvmStatic
|
||||
fun requireSecretKeyFrom(keyRing: PGPSecretKeyRing, subKeyId: Long): PGPSecretKey {
|
||||
return keyRing.getSecretKey(subKeyId)
|
||||
?: throw NoSuchElementException("KeyRing does not contain secret key with keyID ${subKeyId.hexKeyId()}.")
|
||||
?: throw NoSuchElementException("KeyRing does not contain secret key with keyID ${subKeyId.openPgpKeyId()}.")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
@ -233,7 +233,7 @@ class KeyRingUtils {
|
|||
var certificate: PGPPublicKeyRing = secretAndPublicKeys.second
|
||||
|
||||
if (!keyRingContainsKeyWithId(certificate, certifiedKey.keyID)) {
|
||||
throw NoSuchElementException("Cannot find public key with id ${certifiedKey.keyID.hexKeyId()} in the provided key ring.")
|
||||
throw NoSuchElementException("Cannot find public key with id ${certifiedKey.keyID.openPgpKeyId()} in the provided key ring.")
|
||||
}
|
||||
|
||||
certificate = PGPPublicKeyRing(
|
||||
|
@ -389,7 +389,7 @@ class KeyRingUtils {
|
|||
"Bouncy Castle currently cannot deal with stripped primary secret keys."
|
||||
}
|
||||
if (secretKeys.getSecretKey(keyId) == null) {
|
||||
throw NoSuchElementException("PGPSecretKeyRing does not contain secret key ${keyId.hexKeyId()}.")
|
||||
throw NoSuchElementException("PGPSecretKeyRing does not contain secret key ${keyId.openPgpKeyId()}.")
|
||||
}
|
||||
|
||||
val out = ByteArrayOutputStream()
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package org.pgpainless.signature.subpackets
|
||||
|
||||
import _kotlin.hexKeyId
|
||||
import openpgp.openPgpKeyId
|
||||
import org.bouncycastle.bcpg.sig.*
|
||||
import org.bouncycastle.openpgp.PGPPublicKey
|
||||
import org.bouncycastle.openpgp.PGPSignature
|
||||
|
@ -143,7 +143,7 @@ class SignatureSubpacketsUtil {
|
|||
@JvmStatic
|
||||
fun getKeyExpirationTimeAsDate(signature: PGPSignature, signingKey: PGPPublicKey): Date? =
|
||||
require(signature.keyID == signingKey.keyID) {
|
||||
"Provided key (${signingKey.keyID.hexKeyId()}) did not create the signature (${signature.keyID.hexKeyId()})"
|
||||
"Provided key (${signingKey.keyID.openPgpKeyId()}) did not create the signature (${signature.keyID.openPgpKeyId()})"
|
||||
}.run {
|
||||
getKeyExpirationTime(signature)?.let {
|
||||
SignatureUtils.datePlusSeconds(signingKey.creationTime, it.time)
|
||||
|
|
Loading…
Reference in a new issue