1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-13 07:41:08 +01:00

Kotlin conversion: DecryptionBuilder

This commit is contained in:
Paul Schaub 2023-08-30 13:59:34 +02:00
parent 4a19e6ca20
commit 9988ba9940
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 60 additions and 78 deletions

View file

@ -1,42 +0,0 @@
// SPDX-FileCopyrightText: 2018 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.decryption_verification;
import java.io.IOException;
import java.io.InputStream;
import javax.annotation.Nonnull;
import org.bouncycastle.openpgp.PGPException;
/**
* Builder class that takes an {@link InputStream} of ciphertext (or plaintext signed data)
* and combines it with a configured {@link ConsumerOptions} object to form a {@link DecryptionStream} which
* can be used to decrypt an OpenPGP message or verify signatures.
*/
public class DecryptionBuilder implements DecryptionBuilderInterface {
@Override
public DecryptWith onInputStream(@Nonnull InputStream inputStream) {
return new DecryptWithImpl(inputStream);
}
static class DecryptWithImpl implements DecryptWith {
private final InputStream inputStream;
DecryptWithImpl(InputStream inputStream) {
this.inputStream = inputStream;
}
@Override
public DecryptionStream withOptions(ConsumerOptions consumerOptions) throws PGPException, IOException {
if (consumerOptions == null) {
throw new IllegalArgumentException("Consumer options cannot be null.");
}
return OpenPgpMessageInputStream.create(inputStream, consumerOptions);
}
}
}

View file

@ -1,36 +0,0 @@
// SPDX-FileCopyrightText: 2018 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.decryption_verification;
import java.io.IOException;
import java.io.InputStream;
import javax.annotation.Nonnull;
import org.bouncycastle.openpgp.PGPException;
public interface DecryptionBuilderInterface {
/**
* Create a {@link DecryptionStream} on an {@link InputStream} which contains the encrypted and/or signed data.
*
* @param inputStream encrypted and/or signed data.
* @return api handle
*/
DecryptWith onInputStream(@Nonnull InputStream inputStream);
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
*/
DecryptionStream withOptions(ConsumerOptions consumerOptions) throws PGPException, IOException;
}
}