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 f37d4a4450
commit b8bdb5bbe5
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() = get() =
SignatureSubpacketsUtil.parsePreferredCompressionAlgorithms(signatureWithPreferences) SignatureSubpacketsUtil.parsePreferredCompressionAlgorithms(signatureWithPreferences)
/** Preferred AEAD algorithm suites. */
val preferredAEADCipherSuites: Set<AEADCipherMode> val preferredAEADCipherSuites: Set<AEADCipherMode>
get() = SignatureSubpacketsUtil.parsePreferredAEADCipherSuites(signatureWithPreferences) 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) { class ViaKeyId(info: KeyRingInfo, key: SubkeyIdentifier) : KeyAccessor(info, key) {
override val signatureWithPreferences: PGPSignature override val signatureWithPreferences: PGPSignature
get() { get() {
// If the key is located by Key ID, the algorithm of the primary User ID of the key if (key.isPrimaryKey) {
// provides the // If the key is located by Key ID, the algorithm of the primary User ID of the
// preferred symmetric algorithm. // key
info.primaryUserId?.let { userId -> // provides the
info.getLatestUserIdCertification(userId).let { if (it != null) return it } // 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( ?: throw NoSuchElementException(
"Key does not carry acceptable self-signature signature.") "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."
}
}
} }