1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-11 14:17:10 +02:00
pgpainless/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionBuilderInterface.java

90 lines
3.5 KiB
Java
Raw Normal View History

/*
* 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.
*/
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;
import java.util.Date;
2021-04-26 13:38:12 +02:00
import javax.annotation.Nonnull;
2018-06-05 01:30:58 +02:00
import org.bouncycastle.openpgp.PGPException;
import org.pgpainless.algorithm.StreamEncoding;
import org.pgpainless.decryption_verification.OpenPgpMetadata;
2018-06-04 19:45:18 +02:00
public interface EncryptionBuilderInterface {
/**
* 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) {
return onOutputStream(outputStream, OpenPgpMetadata.FileInfo.binaryStream());
}
/**
* 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
*
* @deprecated use {@link #onOutputStream(OutputStream, OpenPgpMetadata.FileInfo)} instead.
*/
2021-06-29 16:43:37 +02:00
default WithOptions onOutputStream(@Nonnull OutputStream outputStream, boolean forYourEyesOnly) {
return onOutputStream(outputStream, forYourEyesOnly ? OpenPgpMetadata.FileInfo.forYourEyesOnly() : OpenPgpMetadata.FileInfo.binaryStream());
}
/**
* 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
*
* @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) {
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-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
/**
2021-05-06 00:04:03 +02:00
* Create an {@link EncryptionStream} with the given options (recipients, signers, algorithms...).
*
2021-05-06 00:04:03 +02:00
* @param options options
* @return encryption strea
*/
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
}