mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
Kotlin conversion: SignatureGenerationStream
This commit is contained in:
parent
0fa09065cf
commit
068aa0ec27
2 changed files with 39 additions and 65 deletions
|
@ -0,0 +1,39 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.encryption_signing
|
||||
|
||||
import java.io.OutputStream
|
||||
|
||||
/**
|
||||
* OutputStream which has the task of updating signature generators for written data.
|
||||
*/
|
||||
class SignatureGenerationStream(
|
||||
private val wrapped: OutputStream,
|
||||
private val options: SigningOptions?
|
||||
) : OutputStream() {
|
||||
|
||||
override fun close() = wrapped.close()
|
||||
override fun flush() = wrapped.flush()
|
||||
|
||||
override fun write(b: Int) {
|
||||
wrapped.write(b)
|
||||
options?.run {
|
||||
signingMethods.values.forEach {
|
||||
it.signatureGenerator.update((b and 0xff).toByte())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun write(b: ByteArray) = write(b, 0, b.size)
|
||||
|
||||
override fun write(b: ByteArray, off: Int, len: Int) {
|
||||
wrapped.write(b, off, len)
|
||||
options?.run {
|
||||
signingMethods.values.forEach {
|
||||
it.signatureGenerator.update(b, off, len)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue