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

Clean up KeyAccessor class

This commit is contained in:
Paul Schaub 2025-02-26 16:25:53 +01:00
parent e53e4f5f3c
commit 22a1f54a9b
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -41,6 +41,7 @@ abstract class KeyAccessor(protected val info: KeyRingInfo, protected val key: S
get() =
SignatureSubpacketsUtil.parsePreferredCompressionAlgorithms(signatureWithPreferences)
/** Preferred AEAD algorithm suites. */
val preferredAEADCipherSuites: Set<AEADCipherMode>
get() = SignatureSubpacketsUtil.parsePreferredAEADCipherSuites(signatureWithPreferences)
@ -64,30 +65,19 @@ abstract class KeyAccessor(protected val info: KeyRingInfo, protected val key: S
class ViaKeyId(info: KeyRingInfo, key: SubkeyIdentifier) : KeyAccessor(info, key) {
override val signatureWithPreferences: PGPSignature
get() {
// If the key is located by Key ID, the algorithm of the primary User ID of the key
// provides the
// preferred symmetric algorithm.
info.primaryUserId?.let { userId ->
info.getLatestUserIdCertification(userId).let { if (it != null) return it }
if (key.isPrimaryKey) {
// If the key is located by Key ID, the algorithm of the primary User ID of the
// key
// provides the
// preferred symmetric algorithm.
info.primaryUserId?.let { userId ->
info.getLatestUserIdCertification(userId).let { if (it != null) return it }
}
}
return info.getCurrentSubkeyBindingSignature(key.subkeyId)
return info.getCurrentSubkeyBindingSignature(key.keyIdentifier)
?: throw NoSuchElementException(
"Key does not carry acceptable self-signature signature.")
}
}
class SubKey(info: KeyRingInfo, key: SubkeyIdentifier) : KeyAccessor(info, key) {
override val signatureWithPreferences: PGPSignature
get() =
checkNotNull(
if (key.isPrimaryKey) {
info.latestDirectKeySelfSignature
?: info.primaryUserId?.let { info.getLatestUserIdCertification(it) }
} else {
info.getCurrentSubkeyBindingSignature(key.subkeyId)
}) {
"No valid signature found."
}
}
}