mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
Kotlin conversion: DecryptionBuilder
This commit is contained in:
parent
4a19e6ca20
commit
9988ba9940
4 changed files with 60 additions and 78 deletions
|
@ -0,0 +1,26 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.decryption_verification
|
||||
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* Builder class that takes an [InputStream] of ciphertext (or plaintext signed data)
|
||||
* and combines it with a configured [ConsumerOptions] object to form a [DecryptionStream] which
|
||||
* can be used to decrypt an OpenPGP message or verify signatures.
|
||||
*/
|
||||
class DecryptionBuilder: DecryptionBuilderInterface {
|
||||
|
||||
override fun onInputStream(inputStream: InputStream): DecryptionBuilderInterface.DecryptWith {
|
||||
return DecryptWithImpl(inputStream)
|
||||
}
|
||||
|
||||
class DecryptWithImpl(val inputStream: InputStream): DecryptionBuilderInterface.DecryptWith {
|
||||
|
||||
override fun withOptions(consumerOptions: ConsumerOptions): DecryptionStream {
|
||||
return OpenPgpMessageInputStream.create(inputStream, consumerOptions)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.decryption_verification
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
interface DecryptionBuilderInterface {
|
||||
|
||||
/**
|
||||
* Create a [DecryptionStream] on an [InputStream] which contains the encrypted and/or signed data.
|
||||
*
|
||||
* @param inputStream encrypted and/or signed data.
|
||||
* @return api handle
|
||||
*/
|
||||
fun onInputStream(inputStream: InputStream): DecryptWith
|
||||
|
||||
interface DecryptWith {
|
||||
|
||||
/**
|
||||
* Add options for decryption / signature verification, such as keys, passphrases etc.
|
||||
*
|
||||
* @param consumerOptions consumer options
|
||||
* @return decryption stream
|
||||
* @throws PGPException in case of an OpenPGP related error
|
||||
* @throws IOException in case of an IO error
|
||||
*/
|
||||
@Throws(PGPException::class, IOException::class)
|
||||
fun withOptions(consumerOptions: ConsumerOptions): DecryptionStream
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue