2018-06-13 17:26:48 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Paul Schaub.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2018-07-18 18:23:06 +02:00
|
|
|
package org.pgpainless.encryption_signing;
|
2018-06-04 19:45:18 +02:00
|
|
|
|
2018-06-05 01:30:58 +02:00
|
|
|
import java.io.IOException;
|
2018-06-04 19:45:18 +02:00
|
|
|
import java.io.OutputStream;
|
2021-04-25 00:28:48 +02:00
|
|
|
import java.util.Date;
|
2021-04-26 13:38:12 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2018-06-28 18:25:11 +02:00
|
|
|
|
2018-06-05 01:30:58 +02:00
|
|
|
import org.bouncycastle.openpgp.PGPException;
|
2021-04-25 00:28:48 +02:00
|
|
|
import org.pgpainless.algorithm.StreamEncoding;
|
2020-08-24 16:00:23 +02:00
|
|
|
import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
2018-06-04 19:45:18 +02:00
|
|
|
|
|
|
|
public interface EncryptionBuilderInterface {
|
|
|
|
|
2020-08-24 16:00:23 +02:00
|
|
|
/**
|
|
|
|
* Create a {@link EncryptionStream} on an {@link OutputStream} that contains the plain data that
|
|
|
|
* shall be encrypted and or signed.
|
|
|
|
*
|
|
|
|
* @param outputStream output stream of the plain data.
|
|
|
|
* @return api handle
|
|
|
|
*/
|
2021-06-29 16:43:37 +02:00
|
|
|
default WithOptions onOutputStream(@Nonnull OutputStream outputStream) {
|
2021-04-25 00:28:48 +02:00
|
|
|
return onOutputStream(outputStream, OpenPgpMetadata.FileInfo.binaryStream());
|
2021-04-07 21:30:51 +02:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Create a {@link EncryptionStream} on an {@link OutputStream} that contains the plain data which shall
|
|
|
|
* be encrypted and/or signed.
|
|
|
|
*
|
|
|
|
* @param outputStream outputStream
|
|
|
|
* @param forYourEyesOnly flag indicating that the data is intended for the recipients eyes only
|
|
|
|
* @return api handle
|
2021-04-25 00:28:48 +02:00
|
|
|
*
|
|
|
|
* @deprecated use {@link #onOutputStream(OutputStream, OpenPgpMetadata.FileInfo)} instead.
|
2021-04-07 21:30:51 +02:00
|
|
|
*/
|
2021-06-29 16:43:37 +02:00
|
|
|
default WithOptions onOutputStream(@Nonnull OutputStream outputStream, boolean forYourEyesOnly) {
|
2021-04-25 00:28:48 +02:00
|
|
|
return onOutputStream(outputStream, forYourEyesOnly ? OpenPgpMetadata.FileInfo.forYourEyesOnly() : OpenPgpMetadata.FileInfo.binaryStream());
|
2021-04-07 21:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a {@link EncryptionStream} on an {@link OutputStream} that contains the plain data which shall
|
|
|
|
* be encrypted and/or signed.
|
|
|
|
*
|
|
|
|
* @param outputStream outputStream
|
|
|
|
* @param fileName name of the file (or "" if the encrypted data is not a file)
|
|
|
|
* @param forYourEyesOnly flag indicating that the data is intended for the recipients eyes only
|
|
|
|
* @return api handle
|
2021-04-25 00:28:48 +02:00
|
|
|
*
|
|
|
|
* @deprecated use {@link #onOutputStream(OutputStream, OpenPgpMetadata.FileInfo)} instead.
|
|
|
|
*/
|
2021-06-29 16:43:37 +02:00
|
|
|
default WithOptions onOutputStream(@Nonnull OutputStream outputStream, String fileName, boolean forYourEyesOnly) {
|
2021-04-25 00:28:48 +02:00
|
|
|
return onOutputStream(outputStream, new OpenPgpMetadata.FileInfo(forYourEyesOnly ? "_CONSOLE" : fileName, new Date(), StreamEncoding.BINARY));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an {@link EncryptionStream} on an {@link OutputStream} that contains the plain data which shall
|
|
|
|
* be encrypted and/or signed.
|
|
|
|
*
|
|
|
|
* @param outputStream outputStream
|
|
|
|
* @param fileInfo file information
|
|
|
|
* @return api handle
|
2021-04-07 21:30:51 +02:00
|
|
|
*/
|
2021-06-29 16:43:37 +02:00
|
|
|
WithOptions onOutputStream(@Nonnull OutputStream outputStream, OpenPgpMetadata.FileInfo fileInfo);
|
2018-06-04 19:45:18 +02:00
|
|
|
|
2021-06-29 16:43:37 +02:00
|
|
|
interface WithOptions {
|
2018-06-04 19:45:18 +02:00
|
|
|
|
2020-08-24 16:00:23 +02:00
|
|
|
/**
|
2021-05-06 00:04:03 +02:00
|
|
|
* Create an {@link EncryptionStream} with the given options (recipients, signers, algorithms...).
|
2020-08-24 16:00:23 +02:00
|
|
|
*
|
2021-05-06 00:04:03 +02:00
|
|
|
* @param options options
|
|
|
|
* @return encryption strea
|
2020-08-24 16:00:23 +02:00
|
|
|
*/
|
2021-05-06 00:04:03 +02:00
|
|
|
EncryptionStream withOptions(ProducerOptions options) throws PGPException, IOException;
|
2018-06-04 19:45:18 +02:00
|
|
|
|
2021-05-06 00:04:03 +02:00
|
|
|
}
|
2018-06-04 19:45:18 +02:00
|
|
|
}
|