1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-25 04:17:59 +01:00

Add SignatureSubpacketCallback.then()

This commit is contained in:
Paul Schaub 2024-01-24 11:27:35 +01:00
parent 54a9b4f258
commit f611f54cad
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -23,4 +23,24 @@ interface SignatureSubpacketCallback<S : BaseSignatureSubpackets> {
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<S>): SignatureSubpacketCallback<S> {
val currCallback = this
return object : SignatureSubpacketCallback<S> {
override fun modifyHashedSubpackets(hashedSubpackets: S) {
currCallback.modifyHashedSubpackets(hashedSubpackets)
nextCallback.modifyHashedSubpackets(hashedSubpackets)
}
override fun modifyUnhashedSubpackets(unhashedSubpackets: S) {
currCallback.modifyUnhashedSubpackets(unhashedSubpackets)
nextCallback.modifyUnhashedSubpackets(unhashedSubpackets)
}
}
}
}