1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-23 12:52:07 +01:00

Do no emit an uncompressed compressed-data-packet

Fixes #74
This commit is contained in:
Paul Schaub 2021-02-17 19:52:30 +01:00
parent d2202dcb0f
commit cb7f38f003
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -207,22 +207,28 @@ public final class EncryptionStream extends OutputStream {
} }
private void prepareCompression() throws IOException { private void prepareCompression() throws IOException {
LOGGER.log(LEVEL, "Compress using " + compressionAlgorithm);
compressedDataGenerator = new PGPCompressedDataGenerator( compressedDataGenerator = new PGPCompressedDataGenerator(
compressionAlgorithm.getAlgorithmId()); compressionAlgorithm.getAlgorithmId());
if (compressionAlgorithm == CompressionAlgorithm.UNCOMPRESSED) {
return;
}
LOGGER.log(LEVEL, "Compress using " + compressionAlgorithm);
basicCompressionStream = new BCPGOutputStream(compressedDataGenerator.open(outermostStream)); basicCompressionStream = new BCPGOutputStream(compressedDataGenerator.open(outermostStream));
outermostStream = basicCompressionStream;
} }
private void prepareOnePassSignatures() throws IOException, PGPException { private void prepareOnePassSignatures() throws IOException, PGPException {
for (PGPSignatureGenerator signatureGenerator : signatureGenerators.values()) { for (PGPSignatureGenerator signatureGenerator : signatureGenerators.values()) {
signatureGenerator.generateOnePassVersion(false).encode(basicCompressionStream); signatureGenerator.generateOnePassVersion(false).encode(outermostStream);
} }
} }
private void prepareLiteralDataProcessing() throws IOException { private void prepareLiteralDataProcessing() throws IOException {
literalDataGenerator = new PGPLiteralDataGenerator(); literalDataGenerator = new PGPLiteralDataGenerator();
literalDataStream = literalDataGenerator.open(basicCompressionStream, literalDataStream = literalDataGenerator.open(outermostStream,
PGPLiteralData.BINARY, PGPLiteralData.CONSOLE, new Date(), new byte[BUFFER_SIZE]); PGPLiteralData.BINARY, PGPLiteralData.CONSOLE, new Date(), new byte[BUFFER_SIZE]);
outermostStream = literalDataStream;
} }
private void prepareResultBuilder() { private void prepareResultBuilder() {
@ -235,7 +241,7 @@ public final class EncryptionStream extends OutputStream {
@Override @Override
public void write(int data) throws IOException { public void write(int data) throws IOException {
literalDataStream.write(data); outermostStream.write(data);
for (PGPSignatureGenerator signatureGenerator : signatureGenerators.values()) { for (PGPSignatureGenerator signatureGenerator : signatureGenerators.values()) {
byte asByte = (byte) (data & 0xff); byte asByte = (byte) (data & 0xff);
@ -251,7 +257,7 @@ public final class EncryptionStream extends OutputStream {
@Override @Override
public void write(byte[] buffer, int off, int len) throws IOException { public void write(byte[] buffer, int off, int len) throws IOException {
literalDataStream.write(buffer, 0, len); outermostStream.write(buffer, 0, len);
for (PGPSignatureGenerator signatureGenerator : signatureGenerators.values()) { for (PGPSignatureGenerator signatureGenerator : signatureGenerators.values()) {
signatureGenerator.update(buffer, 0, len); signatureGenerator.update(buffer, 0, len);
} }
@ -259,7 +265,7 @@ public final class EncryptionStream extends OutputStream {
@Override @Override
public void flush() throws IOException { public void flush() throws IOException {
literalDataStream.flush(); outermostStream.flush();
} }
@Override @Override
@ -298,7 +304,7 @@ public final class EncryptionStream extends OutputStream {
try { try {
PGPSignature signature = signatureGenerator.generate(); PGPSignature signature = signatureGenerator.generate();
if (!detachedSignature) { if (!detachedSignature) {
signature.encode(basicCompressionStream); signature.encode(outermostStream);
} }
resultBuilder.addDetachedSignature(new DetachedSignature(signature, fingerprint)); resultBuilder.addDetachedSignature(new DetachedSignature(signature, fingerprint));
} catch (PGPException e) { } catch (PGPException e) {