From f611f54cadfebc80da34a8c735c7464a69cfbfc9 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 24 Jan 2024 11:27:35 +0100 Subject: [PATCH] Add SignatureSubpacketCallback.then() --- .../subpackets/SignatureSubpacketCallback.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/signature/subpackets/SignatureSubpacketCallback.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/signature/subpackets/SignatureSubpacketCallback.kt index fbc56035..53760d92 100644 --- a/pgpainless-core/src/main/kotlin/org/pgpainless/signature/subpackets/SignatureSubpacketCallback.kt +++ b/pgpainless-core/src/main/kotlin/org/pgpainless/signature/subpackets/SignatureSubpacketCallback.kt @@ -23,4 +23,24 @@ interface SignatureSubpacketCallback { fun modifyUnhashedSubpackets(unhashedSubpackets: S) { // Empty default implementation to allow for cleaner overriding } + + /** + * Return a new [SignatureSubpacketCallback] which first applies the current callback instance, + * followed by the passed in [nextCallback]. + * This is useful to composite different [SignatureSubpacketCallback] instances. + */ + fun then(nextCallback: SignatureSubpacketCallback): SignatureSubpacketCallback { + val currCallback = this + return object : SignatureSubpacketCallback { + override fun modifyHashedSubpackets(hashedSubpackets: S) { + currCallback.modifyHashedSubpackets(hashedSubpackets) + nextCallback.modifyHashedSubpackets(hashedSubpackets) + } + + override fun modifyUnhashedSubpackets(unhashedSubpackets: S) { + currCallback.modifyUnhashedSubpackets(unhashedSubpackets) + nextCallback.modifyUnhashedSubpackets(unhashedSubpackets) + } + } + } }