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

Replace usage of KeyIdentifier.matches() with matchesExplicitly()

This commit is contained in:
Paul Schaub 2025-05-21 11:57:13 +02:00
parent 46367aff93
commit 65e2de8186
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
12 changed files with 22 additions and 18 deletions

View file

@ -190,7 +190,9 @@ class GnuPGDummyKeyUtil private constructor() {
* @return filter * @return filter
*/ */
@JvmStatic @JvmStatic
fun only(onlyKeyIdentifier: KeyIdentifier) = KeyFilter { it.matches(onlyKeyIdentifier) } fun only(onlyKeyIdentifier: KeyIdentifier) = KeyFilter {
it.matchesExplicit(onlyKeyIdentifier)
}
/** /**
* Select all keyIds which are contained in the given set of ids. * Select all keyIds which are contained in the given set of ids.

View file

@ -23,7 +23,7 @@ import org.pgpainless.key.SubkeyIdentifier
* @return true if the [PGPKeyRing] contains the [SubkeyIdentifier] * @return true if the [PGPKeyRing] contains the [SubkeyIdentifier]
*/ */
fun PGPKeyRing.matches(subkeyIdentifier: SubkeyIdentifier): Boolean = fun PGPKeyRing.matches(subkeyIdentifier: SubkeyIdentifier): Boolean =
this.publicKey.keyIdentifier.matches(subkeyIdentifier.certificateIdentifier) && this.publicKey.keyIdentifier.matchesExplicit(subkeyIdentifier.certificateIdentifier) &&
this.getPublicKey(subkeyIdentifier.componentKeyIdentifier) != null this.getPublicKey(subkeyIdentifier.componentKeyIdentifier) != null
/** /**

View file

@ -709,7 +709,7 @@ class OpenPgpMessageInputStream(
options.getDecryptionKeys().firstOrNull { options.getDecryptionKeys().firstOrNull {
it.pgpSecretKeyRing.getSecretKeyFor(pkesk) != null && it.pgpSecretKeyRing.getSecretKeyFor(pkesk) != null &&
api.inspect(it).decryptionSubkeys.any { subkey -> api.inspect(it).decryptionSubkeys.any { subkey ->
pkesk.keyIdentifier.matches(subkey.keyIdentifier) pkesk.keyIdentifier.matchesExplicit(subkey.keyIdentifier)
} }
} }
@ -717,7 +717,7 @@ class OpenPgpMessageInputStream(
options.getDecryptionKeys().filter { options.getDecryptionKeys().filter {
it.pgpSecretKeyRing.getSecretKeyFor(pkesk) != null && it.pgpSecretKeyRing.getSecretKeyFor(pkesk) != null &&
api.inspect(it).decryptionSubkeys.any { subkey -> api.inspect(it).decryptionSubkeys.any { subkey ->
pkesk.keyIdentifier.matches(subkey.keyIdentifier) pkesk.keyIdentifier.matchesExplicit(subkey.keyIdentifier)
} }
} }

View file

@ -14,7 +14,7 @@ class OpenPGPSignatureSet<S : OpenPGPSignature>(val signatures: List<S>) : Itera
fun getSignaturesBy(componentKey: OpenPGPCertificate.OpenPGPComponentKey): List<S> = fun getSignaturesBy(componentKey: OpenPGPCertificate.OpenPGPComponentKey): List<S> =
signatures.filter { sig -> signatures.filter { sig ->
sig.signature.keyIdentifiers.any { componentKey.keyIdentifier.matches(it) } sig.signature.keyIdentifiers.any { componentKey.keyIdentifier.matchesExplicit(it) }
} }
override fun iterator(): Iterator<S> { override fun iterator(): Iterator<S> {

View file

@ -262,7 +262,7 @@ class SigningOptions(private val api: PGPainless) {
throw UnacceptableSigningKeyException(openPGPKey) throw UnacceptableSigningKeyException(openPGPKey)
} }
if (!signingPubKeys.any { it.keyIdentifier.matches(signingKey.keyIdentifier) }) { if (!signingPubKeys.any { it.keyIdentifier.matchesExplicit(signingKey.keyIdentifier) }) {
throw MissingSecretKeyException(signingKey) throw MissingSecretKeyException(signingKey)
} }

View file

@ -127,7 +127,7 @@ class SubkeyIdentifier(
@Deprecated("Use of key-ids is discouraged.") val primaryKeyId = certificateIdentifier.keyId @Deprecated("Use of key-ids is discouraged.") val primaryKeyId = certificateIdentifier.keyId
/** True, if the component key is the primary key. */ /** True, if the component key is the primary key. */
val isPrimaryKey = certificateIdentifier.matches(componentKeyIdentifier) val isPrimaryKey = certificateIdentifier.matchesExplicit(componentKeyIdentifier)
/** /**
* Return true, if the provided [fingerprint] matches either the [certificateFingerprint] or * Return true, if the provided [fingerprint] matches either the [certificateFingerprint] or

View file

@ -167,7 +167,7 @@ class KeyRingInfo(
keys.keys keys.keys
.asSequence() .asSequence()
.filter { .filter {
if (!it.keyIdentifier.matches(keyIdentifier)) { if (!it.keyIdentifier.matchesExplicit(keyIdentifier)) {
if (it.getLatestSelfSignature(referenceDate) == null) { if (it.getLatestSelfSignature(referenceDate) == null) {
LOGGER.debug("Subkey ${it.keyIdentifier} has no binding signature.") LOGGER.debug("Subkey ${it.keyIdentifier} has no binding signature.")
return@filter false return@filter false
@ -281,7 +281,7 @@ class KeyRingInfo(
* @return expiration date * @return expiration date
*/ */
fun getSubkeyExpirationDate(keyIdentifier: KeyIdentifier): Date? { fun getSubkeyExpirationDate(keyIdentifier: KeyIdentifier): Date? {
if (primaryKey.keyIdentifier.matches(keyIdentifier)) return primaryKeyExpirationDate if (primaryKey.keyIdentifier.matchesExplicit(keyIdentifier)) return primaryKeyExpirationDate
val subkey = val subkey =
getPublicKey(keyIdentifier) getPublicKey(keyIdentifier)
?: throw NoSuchElementException("No subkey with key-ID ${keyIdentifier} found.") ?: throw NoSuchElementException("No subkey with key-ID ${keyIdentifier} found.")
@ -522,7 +522,7 @@ class KeyRingInfo(
* @return list of key flags * @return list of key flags
*/ */
fun getKeyFlagsOf(keyIdentifier: KeyIdentifier): List<KeyFlag> = fun getKeyFlagsOf(keyIdentifier: KeyIdentifier): List<KeyFlag> =
if (primaryKey.keyIdentifier.matches(keyIdentifier)) { if (primaryKey.keyIdentifier.matchesExplicit(keyIdentifier)) {
latestDirectKeySelfSignature?.let { sig -> latestDirectKeySelfSignature?.let { sig ->
SignatureSubpacketsUtil.parseKeyFlags(sig)?.let { flags -> SignatureSubpacketsUtil.parseKeyFlags(sig)?.let { flags ->
return flags return flags
@ -655,7 +655,7 @@ class KeyRingInfo(
* key of the key. * key of the key.
*/ */
fun getPublicKey(identifier: SubkeyIdentifier): OpenPGPComponentKey? { fun getPublicKey(identifier: SubkeyIdentifier): OpenPGPComponentKey? {
require(primaryKey.keyIdentifier.matches(identifier.keyIdentifier)) { require(primaryKey.keyIdentifier.matchesExplicit(identifier.keyIdentifier)) {
"Mismatching primary key ID." "Mismatching primary key ID."
} }
return getPublicKey(identifier.componentKeyIdentifier) return getPublicKey(identifier.componentKeyIdentifier)
@ -669,7 +669,7 @@ class KeyRingInfo(
* key of the key. * key of the key.
*/ */
fun getSecretKey(identifier: SubkeyIdentifier): OpenPGPComponentKey? { fun getSecretKey(identifier: SubkeyIdentifier): OpenPGPComponentKey? {
require(primaryKey.keyIdentifier.matches(identifier.keyIdentifier)) { require(primaryKey.keyIdentifier.matchesExplicit(identifier.keyIdentifier)) {
"Mismatching primary key ID." "Mismatching primary key ID."
} }
return getSecretKey(identifier.componentKeyIdentifier) return getSecretKey(identifier.componentKeyIdentifier)

View file

@ -522,7 +522,7 @@ class SecretKeyRingEditor(
var secretKeyRing = key.pgpSecretKeyRing var secretKeyRing = key.pgpSecretKeyRing
// is primary key // is primary key
if (keyId.matches(key.keyIdentifier)) { if (keyId.matchesExplicit(key.keyIdentifier)) {
return setExpirationDate(expiration, protector) return setExpirationDate(expiration, protector)
} }

View file

@ -85,7 +85,7 @@ class PasswordBasedSecretKeyRingProtector : BaseSecretKeyRingProtector {
} }
override fun hasPassphrase(keyIdentifier: KeyIdentifier): Boolean { override fun hasPassphrase(keyIdentifier: KeyIdentifier): Boolean {
return keyIdentifier.matches(singleKeyIdentifier) return keyIdentifier.matchesExplicit(singleKeyIdentifier)
} }
} }
.let { PasswordBasedSecretKeyRingProtector(it) } .let { PasswordBasedSecretKeyRingProtector(it) }

View file

@ -495,7 +495,7 @@ class KeyRingUtils {
secretKeys.secretKeys secretKeys.secretKeys
.asSequence() .asSequence()
.map { .map {
if (it.keyIdentifier.matches(keyId)) { if (it.keyIdentifier.matchesExplicit(keyId)) {
reencryptPrivateKey(it, oldProtector, newProtector) reencryptPrivateKey(it, oldProtector, newProtector)
} else { } else {
it it

View file

@ -49,7 +49,8 @@ class Policy {
this.keyGenerationAlgorithmSuite = keyGenerationAlgorithmSuite this.keyGenerationAlgorithmSuite = keyGenerationAlgorithmSuite
} }
@Deprecated("Constructors receiving SymmetricKeyAlgorithmPolicy objects are deprecated in favor of ones receiving MessageEncryptionMechanismPolicy objects.") @Deprecated(
"Constructors receiving SymmetricKeyAlgorithmPolicy objects are deprecated in favor of ones receiving MessageEncryptionMechanismPolicy objects.")
constructor( constructor(
certificationSignatureHashAlgorithmPolicy: HashAlgorithmPolicy, certificationSignatureHashAlgorithmPolicy: HashAlgorithmPolicy,
revocationSignatureHashAlgorithmPolicy: HashAlgorithmPolicy, revocationSignatureHashAlgorithmPolicy: HashAlgorithmPolicy,
@ -78,7 +79,8 @@ class Policy {
this.keyGenerationAlgorithmSuite = keyGenerationAlgorithmSuite this.keyGenerationAlgorithmSuite = keyGenerationAlgorithmSuite
} }
@Deprecated("Constructors receiving SymmetricKeyAlgorithmPolicy objects are deprecated in favor of ones receiving MessageEncryptionMechanismPolicy objects.") @Deprecated(
"Constructors receiving SymmetricKeyAlgorithmPolicy objects are deprecated in favor of ones receiving MessageEncryptionMechanismPolicy objects.")
constructor() : constructor() :
this( this(
HashAlgorithmPolicy.smartCertificationSignatureHashAlgorithmPolicy(), HashAlgorithmPolicy.smartCertificationSignatureHashAlgorithmPolicy(),

View file

@ -178,7 +178,7 @@ public class ModifyKeys {
List<OpenPGPCertificate.OpenPGPComponentKey> encryptionSubkeys = info.getEncryptionSubkeys(EncryptionPurpose.COMMUNICATIONS); List<OpenPGPCertificate.OpenPGPComponentKey> encryptionSubkeys = info.getEncryptionSubkeys(EncryptionPurpose.COMMUNICATIONS);
assertEquals(2, encryptionSubkeys.size()); assertEquals(2, encryptionSubkeys.size());
OpenPGPCertificate.OpenPGPComponentKey addedKey = encryptionSubkeys.stream() OpenPGPCertificate.OpenPGPComponentKey addedKey = encryptionSubkeys.stream()
.filter(it -> !it.getKeyIdentifier().matches(encryptionSubkeyId)).findFirst() .filter(it -> !it.getKeyIdentifier().matchesExplicit(encryptionSubkeyId)).findFirst()
.get(); .get();
UnlockSecretKey.unlockSecretKey(secretKey.getSecretKey(addedKey.getKeyIdentifier()).getPGPSecretKey(), subkeyPassphrase); UnlockSecretKey.unlockSecretKey(secretKey.getSecretKey(addedKey.getKeyIdentifier()).getPGPSecretKey(), subkeyPassphrase);
} }