mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-27 06:42:05 +01:00
Allow specification of file name and for-your-eyes-only flag
This commit is contained in:
parent
d082f126b3
commit
cd19f91d77
3 changed files with 43 additions and 7 deletions
|
@ -68,6 +68,8 @@ public class EncryptionBuilder implements EncryptionBuilderInterface {
|
||||||
private HashAlgorithm hashAlgorithm = HashAlgorithm.SHA256;
|
private HashAlgorithm hashAlgorithm = HashAlgorithm.SHA256;
|
||||||
private CompressionAlgorithm compressionAlgorithm = CompressionAlgorithm.UNCOMPRESSED;
|
private CompressionAlgorithm compressionAlgorithm = CompressionAlgorithm.UNCOMPRESSED;
|
||||||
private boolean asciiArmor = false;
|
private boolean asciiArmor = false;
|
||||||
|
private String fileName;
|
||||||
|
private boolean forYourEyesOnly;
|
||||||
|
|
||||||
public EncryptionBuilder() {
|
public EncryptionBuilder() {
|
||||||
this.purpose = EncryptionStream.Purpose.COMMUNICATIONS;
|
this.purpose = EncryptionStream.Purpose.COMMUNICATIONS;
|
||||||
|
@ -78,8 +80,10 @@ public class EncryptionBuilder implements EncryptionBuilderInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ToRecipients onOutputStream(@Nonnull OutputStream outputStream) {
|
public ToRecipients onOutputStream(@Nonnull OutputStream outputStream, String fileName, boolean forYourEyesOnly) {
|
||||||
this.outputStream = outputStream;
|
this.outputStream = outputStream;
|
||||||
|
this.fileName = fileName == null ? "" : fileName;
|
||||||
|
this.forYourEyesOnly = forYourEyesOnly;
|
||||||
return new ToRecipientsImpl();
|
return new ToRecipientsImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,7 +434,9 @@ public class EncryptionBuilder implements EncryptionBuilderInterface {
|
||||||
EncryptionBuilder.this.symmetricKeyAlgorithm,
|
EncryptionBuilder.this.symmetricKeyAlgorithm,
|
||||||
EncryptionBuilder.this.hashAlgorithm,
|
EncryptionBuilder.this.hashAlgorithm,
|
||||||
EncryptionBuilder.this.compressionAlgorithm,
|
EncryptionBuilder.this.compressionAlgorithm,
|
||||||
EncryptionBuilder.this.asciiArmor);
|
EncryptionBuilder.this.asciiArmor,
|
||||||
|
fileName,
|
||||||
|
forYourEyesOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,31 @@ public interface EncryptionBuilderInterface {
|
||||||
* @param outputStream output stream of the plain data.
|
* @param outputStream output stream of the plain data.
|
||||||
* @return api handle
|
* @return api handle
|
||||||
*/
|
*/
|
||||||
ToRecipients onOutputStream(@Nonnull OutputStream outputStream);
|
default ToRecipients onOutputStream(@Nonnull OutputStream outputStream) {
|
||||||
|
return onOutputStream(outputStream,false);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
default ToRecipients onOutputStream(@Nonnull OutputStream outputStream, boolean forYourEyesOnly) {
|
||||||
|
return onOutputStream(outputStream, "", forYourEyesOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
ToRecipients onOutputStream(@Nonnull OutputStream outputStream, String fileName, boolean forYourEyesOnly);
|
||||||
|
|
||||||
interface ToRecipients {
|
interface ToRecipients {
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,9 @@ public final class EncryptionStream extends OutputStream {
|
||||||
@Nonnull SymmetricKeyAlgorithm symmetricKeyAlgorithm,
|
@Nonnull SymmetricKeyAlgorithm symmetricKeyAlgorithm,
|
||||||
@Nonnull HashAlgorithm hashAlgorithm,
|
@Nonnull HashAlgorithm hashAlgorithm,
|
||||||
@Nonnull CompressionAlgorithm compressionAlgorithm,
|
@Nonnull CompressionAlgorithm compressionAlgorithm,
|
||||||
boolean asciiArmor)
|
boolean asciiArmor,
|
||||||
|
@Nonnull String fileName,
|
||||||
|
boolean forYourEyesOnly)
|
||||||
throws IOException, PGPException {
|
throws IOException, PGPException {
|
||||||
|
|
||||||
this.symmetricKeyAlgorithm = symmetricKeyAlgorithm;
|
this.symmetricKeyAlgorithm = symmetricKeyAlgorithm;
|
||||||
|
@ -136,7 +138,7 @@ public final class EncryptionStream extends OutputStream {
|
||||||
prepareSigning();
|
prepareSigning();
|
||||||
prepareCompression();
|
prepareCompression();
|
||||||
prepareOnePassSignatures();
|
prepareOnePassSignatures();
|
||||||
prepareLiteralDataProcessing();
|
prepareLiteralDataProcessing(fileName, forYourEyesOnly);
|
||||||
prepareResultBuilder();
|
prepareResultBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,10 +227,14 @@ public final class EncryptionStream extends OutputStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareLiteralDataProcessing() throws IOException {
|
private void prepareLiteralDataProcessing(@Nonnull String fileName, boolean forYourEyesOnly) throws IOException {
|
||||||
literalDataGenerator = new PGPLiteralDataGenerator();
|
literalDataGenerator = new PGPLiteralDataGenerator();
|
||||||
|
String name = fileName;
|
||||||
|
if (forYourEyesOnly) {
|
||||||
|
name = PGPLiteralData.CONSOLE;
|
||||||
|
}
|
||||||
literalDataStream = literalDataGenerator.open(outermostStream,
|
literalDataStream = literalDataGenerator.open(outermostStream,
|
||||||
PGPLiteralData.BINARY, PGPLiteralData.CONSOLE, new Date(), new byte[BUFFER_SIZE]);
|
PGPLiteralData.BINARY, name, new Date(), new byte[BUFFER_SIZE]);
|
||||||
outermostStream = literalDataStream;
|
outermostStream = literalDataStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue