mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 10:19:39 +02:00
Replace usage of KeyIdentifier.matches() with matchesExplicitly()
This commit is contained in:
parent
46367aff93
commit
65e2de8186
12 changed files with 22 additions and 18 deletions
|
@ -190,7 +190,9 @@ class GnuPGDummyKeyUtil private constructor() {
|
|||
* @return filter
|
||||
*/
|
||||
@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.
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.pgpainless.key.SubkeyIdentifier
|
|||
* @return true if the [PGPKeyRing] contains the [SubkeyIdentifier]
|
||||
*/
|
||||
fun PGPKeyRing.matches(subkeyIdentifier: SubkeyIdentifier): Boolean =
|
||||
this.publicKey.keyIdentifier.matches(subkeyIdentifier.certificateIdentifier) &&
|
||||
this.publicKey.keyIdentifier.matchesExplicit(subkeyIdentifier.certificateIdentifier) &&
|
||||
this.getPublicKey(subkeyIdentifier.componentKeyIdentifier) != null
|
||||
|
||||
/**
|
||||
|
|
|
@ -709,7 +709,7 @@ class OpenPgpMessageInputStream(
|
|||
options.getDecryptionKeys().firstOrNull {
|
||||
it.pgpSecretKeyRing.getSecretKeyFor(pkesk) != null &&
|
||||
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 {
|
||||
it.pgpSecretKeyRing.getSecretKeyFor(pkesk) != null &&
|
||||
api.inspect(it).decryptionSubkeys.any { subkey ->
|
||||
pkesk.keyIdentifier.matches(subkey.keyIdentifier)
|
||||
pkesk.keyIdentifier.matchesExplicit(subkey.keyIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class OpenPGPSignatureSet<S : OpenPGPSignature>(val signatures: List<S>) : Itera
|
|||
|
||||
fun getSignaturesBy(componentKey: OpenPGPCertificate.OpenPGPComponentKey): List<S> =
|
||||
signatures.filter { sig ->
|
||||
sig.signature.keyIdentifiers.any { componentKey.keyIdentifier.matches(it) }
|
||||
sig.signature.keyIdentifiers.any { componentKey.keyIdentifier.matchesExplicit(it) }
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<S> {
|
||||
|
|
|
@ -262,7 +262,7 @@ class SigningOptions(private val api: PGPainless) {
|
|||
throw UnacceptableSigningKeyException(openPGPKey)
|
||||
}
|
||||
|
||||
if (!signingPubKeys.any { it.keyIdentifier.matches(signingKey.keyIdentifier) }) {
|
||||
if (!signingPubKeys.any { it.keyIdentifier.matchesExplicit(signingKey.keyIdentifier) }) {
|
||||
throw MissingSecretKeyException(signingKey)
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ class SubkeyIdentifier(
|
|||
@Deprecated("Use of key-ids is discouraged.") val primaryKeyId = certificateIdentifier.keyId
|
||||
|
||||
/** 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
|
||||
|
|
|
@ -167,7 +167,7 @@ class KeyRingInfo(
|
|||
keys.keys
|
||||
.asSequence()
|
||||
.filter {
|
||||
if (!it.keyIdentifier.matches(keyIdentifier)) {
|
||||
if (!it.keyIdentifier.matchesExplicit(keyIdentifier)) {
|
||||
if (it.getLatestSelfSignature(referenceDate) == null) {
|
||||
LOGGER.debug("Subkey ${it.keyIdentifier} has no binding signature.")
|
||||
return@filter false
|
||||
|
@ -281,7 +281,7 @@ class KeyRingInfo(
|
|||
* @return expiration date
|
||||
*/
|
||||
fun getSubkeyExpirationDate(keyIdentifier: KeyIdentifier): Date? {
|
||||
if (primaryKey.keyIdentifier.matches(keyIdentifier)) return primaryKeyExpirationDate
|
||||
if (primaryKey.keyIdentifier.matchesExplicit(keyIdentifier)) return primaryKeyExpirationDate
|
||||
val subkey =
|
||||
getPublicKey(keyIdentifier)
|
||||
?: throw NoSuchElementException("No subkey with key-ID ${keyIdentifier} found.")
|
||||
|
@ -522,7 +522,7 @@ class KeyRingInfo(
|
|||
* @return list of key flags
|
||||
*/
|
||||
fun getKeyFlagsOf(keyIdentifier: KeyIdentifier): List<KeyFlag> =
|
||||
if (primaryKey.keyIdentifier.matches(keyIdentifier)) {
|
||||
if (primaryKey.keyIdentifier.matchesExplicit(keyIdentifier)) {
|
||||
latestDirectKeySelfSignature?.let { sig ->
|
||||
SignatureSubpacketsUtil.parseKeyFlags(sig)?.let { flags ->
|
||||
return flags
|
||||
|
@ -655,7 +655,7 @@ class KeyRingInfo(
|
|||
* key of the key.
|
||||
*/
|
||||
fun getPublicKey(identifier: SubkeyIdentifier): OpenPGPComponentKey? {
|
||||
require(primaryKey.keyIdentifier.matches(identifier.keyIdentifier)) {
|
||||
require(primaryKey.keyIdentifier.matchesExplicit(identifier.keyIdentifier)) {
|
||||
"Mismatching primary key ID."
|
||||
}
|
||||
return getPublicKey(identifier.componentKeyIdentifier)
|
||||
|
@ -669,7 +669,7 @@ class KeyRingInfo(
|
|||
* key of the key.
|
||||
*/
|
||||
fun getSecretKey(identifier: SubkeyIdentifier): OpenPGPComponentKey? {
|
||||
require(primaryKey.keyIdentifier.matches(identifier.keyIdentifier)) {
|
||||
require(primaryKey.keyIdentifier.matchesExplicit(identifier.keyIdentifier)) {
|
||||
"Mismatching primary key ID."
|
||||
}
|
||||
return getSecretKey(identifier.componentKeyIdentifier)
|
||||
|
|
|
@ -522,7 +522,7 @@ class SecretKeyRingEditor(
|
|||
var secretKeyRing = key.pgpSecretKeyRing
|
||||
|
||||
// is primary key
|
||||
if (keyId.matches(key.keyIdentifier)) {
|
||||
if (keyId.matchesExplicit(key.keyIdentifier)) {
|
||||
return setExpirationDate(expiration, protector)
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ class PasswordBasedSecretKeyRingProtector : BaseSecretKeyRingProtector {
|
|||
}
|
||||
|
||||
override fun hasPassphrase(keyIdentifier: KeyIdentifier): Boolean {
|
||||
return keyIdentifier.matches(singleKeyIdentifier)
|
||||
return keyIdentifier.matchesExplicit(singleKeyIdentifier)
|
||||
}
|
||||
}
|
||||
.let { PasswordBasedSecretKeyRingProtector(it) }
|
||||
|
|
|
@ -495,7 +495,7 @@ class KeyRingUtils {
|
|||
secretKeys.secretKeys
|
||||
.asSequence()
|
||||
.map {
|
||||
if (it.keyIdentifier.matches(keyId)) {
|
||||
if (it.keyIdentifier.matchesExplicit(keyId)) {
|
||||
reencryptPrivateKey(it, oldProtector, newProtector)
|
||||
} else {
|
||||
it
|
||||
|
|
|
@ -49,7 +49,8 @@ class Policy {
|
|||
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(
|
||||
certificationSignatureHashAlgorithmPolicy: HashAlgorithmPolicy,
|
||||
revocationSignatureHashAlgorithmPolicy: HashAlgorithmPolicy,
|
||||
|
@ -78,7 +79,8 @@ class Policy {
|
|||
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() :
|
||||
this(
|
||||
HashAlgorithmPolicy.smartCertificationSignatureHashAlgorithmPolicy(),
|
||||
|
|
|
@ -178,7 +178,7 @@ public class ModifyKeys {
|
|||
List<OpenPGPCertificate.OpenPGPComponentKey> encryptionSubkeys = info.getEncryptionSubkeys(EncryptionPurpose.COMMUNICATIONS);
|
||||
assertEquals(2, encryptionSubkeys.size());
|
||||
OpenPGPCertificate.OpenPGPComponentKey addedKey = encryptionSubkeys.stream()
|
||||
.filter(it -> !it.getKeyIdentifier().matches(encryptionSubkeyId)).findFirst()
|
||||
.filter(it -> !it.getKeyIdentifier().matchesExplicit(encryptionSubkeyId)).findFirst()
|
||||
.get();
|
||||
UnlockSecretKey.unlockSecretKey(secretKey.getSecretKey(addedKey.getKeyIdentifier()).getPGPSecretKey(), subkeyPassphrase);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue