mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-22 04:12:06 +01:00
Add EncryptionBuilder.discardOutput()
Also move NullOutputStream from pgpainless-sop to pgpainless-core
This commit is contained in:
parent
80cf1a7446
commit
b96f22d0a9
4 changed files with 18 additions and 8 deletions
|
@ -9,6 +9,7 @@ import org.pgpainless.PGPainless.Companion.getPolicy
|
|||
import org.pgpainless.algorithm.CompressionAlgorithm
|
||||
import org.pgpainless.algorithm.SymmetricKeyAlgorithm
|
||||
import org.pgpainless.algorithm.negotiation.SymmetricKeyAlgorithmNegotiator.Companion.byPopularity
|
||||
import org.pgpainless.util.NullOutputStream
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
|
@ -19,6 +20,10 @@ class EncryptionBuilder : EncryptionBuilderInterface {
|
|||
return WithOptionsImpl(outputStream)
|
||||
}
|
||||
|
||||
override fun discardOutput(): EncryptionBuilderInterface.WithOptions {
|
||||
return onOutputStream(NullOutputStream())
|
||||
}
|
||||
|
||||
class WithOptionsImpl(val outputStream: OutputStream) : EncryptionBuilderInterface.WithOptions {
|
||||
|
||||
override fun withOptions(options: ProducerOptions): EncryptionStream {
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.io.IOException
|
|||
import java.io.OutputStream
|
||||
import org.bouncycastle.openpgp.PGPException
|
||||
|
||||
fun interface EncryptionBuilderInterface {
|
||||
interface EncryptionBuilderInterface {
|
||||
|
||||
/**
|
||||
* Create a [EncryptionStream] wrapping an [OutputStream]. Data that is piped through the
|
||||
|
@ -19,6 +19,16 @@ fun interface EncryptionBuilderInterface {
|
|||
*/
|
||||
fun onOutputStream(outputStream: OutputStream): WithOptions
|
||||
|
||||
/**
|
||||
* Create an [EncryptionStream] that discards the data after processing it. This is useful, e.g.
|
||||
* for generating detached signatures, where the resulting signature is retrieved from the
|
||||
* [EncryptionResult] once the operation is finished. In this case, the plaintext data does not
|
||||
* need to be retained.
|
||||
*
|
||||
* @return api handle
|
||||
*/
|
||||
fun discardOutput(): WithOptions
|
||||
|
||||
fun interface WithOptions {
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.sop
|
||||
package org.pgpainless.util
|
||||
|
||||
import java.io.OutputStream
|
||||
|
|
@ -53,15 +53,10 @@ class DetachedSignImpl : DetachedSign {
|
|||
}
|
||||
}
|
||||
|
||||
// When creating a detached signature, the output of the signing stream is actually
|
||||
// the unmodified plaintext data, so we can discard it.
|
||||
// The detached signature will later be retrieved from the metadata object instead.
|
||||
val sink = NullOutputStream()
|
||||
|
||||
try {
|
||||
val signingStream =
|
||||
PGPainless.encryptAndOrSign()
|
||||
.onOutputStream(sink)
|
||||
.discardOutput()
|
||||
.withOptions(ProducerOptions.sign(signingOptions).setAsciiArmor(armor))
|
||||
|
||||
return object : ReadyWithResult<SigningResult>() {
|
||||
|
|
Loading…
Reference in a new issue