1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-25 22:02:05 +01:00

Revert introduction of StreamUtil

This commit is contained in:
Paul Schaub 2021-07-31 20:40:31 +02:00
parent b8f719d3eb
commit 311c842196
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
27 changed files with 78 additions and 137 deletions

View file

@ -127,7 +127,7 @@ Still it allows you to manually specify which algorithms to use of course.
).setAsciiArmor(true) // Ascii armor or not
);
StreamUtil.pipeAll(plaintextInputStream, encryptionStream);
Streams.pipeAll(plaintextInputStream, encryptionStream);
encryptionStream.close();
```
@ -147,7 +147,7 @@ This behaviour can be modified though using the `Policy` class.
.addVerificationCert(alicePubKeys)
);
StreamUtil.pipeAll(decryptionStream, outputStream);
Streams.pipeAll(decryptionStream, outputStream);
decryptionStream.close();
// Result contains information like signature status etc.

View file

@ -36,6 +36,7 @@ import com.ginsberg.junit.exit.FailOnSystemExit;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@ -45,7 +46,6 @@ import org.pgpainless.cli.TestUtils;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.util.StreamUtil;
public class SignVerifyTest {
@ -71,7 +71,7 @@ public class SignVerifyTest {
PGPSecretKeyRing aliceKeys = PGPainless.generateKeyRing()
.modernKeyRing("alice", null);
OutputStream aliceKeyOut = new FileOutputStream(aliceKeyFile);
StreamUtil.pipeAll(new ByteArrayInputStream(aliceKeys.getEncoded()), aliceKeyOut);
Streams.pipeAll(new ByteArrayInputStream(aliceKeys.getEncoded()), aliceKeyOut);
aliceKeyOut.close();
// Write alice pub key to disc
@ -79,14 +79,14 @@ public class SignVerifyTest {
assertTrue(aliceCertFile.createNewFile());
PGPPublicKeyRing alicePub = KeyRingUtils.publicKeyRingFrom(aliceKeys);
OutputStream aliceCertOut = new FileOutputStream(aliceCertFile);
StreamUtil.pipeAll(new ByteArrayInputStream(alicePub.getEncoded()), aliceCertOut);
Streams.pipeAll(new ByteArrayInputStream(alicePub.getEncoded()), aliceCertOut);
aliceCertOut.close();
// Write test data to disc
File dataFile = new File(tempDir, "data");
assertTrue(dataFile.createNewFile());
FileOutputStream dataOut = new FileOutputStream(dataFile);
StreamUtil.pipeAll(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)), dataOut);
Streams.pipeAll(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)), dataOut);
dataOut.close();
// Sign test data

View file

@ -35,10 +35,10 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
import org.bouncycastle.util.io.Streams;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.collection.PGPKeyRingCollection;
import org.pgpainless.util.ArmoredInputStreamFactory;
import org.pgpainless.util.StreamUtil;
public class KeyRingReader {
@ -176,7 +176,7 @@ public class KeyRingReader {
continue;
}
if (next instanceof PGPSecretKeyRing) {
StreamUtil.drain(decoderStream);
Streams.drain(decoderStream);
return (PGPSecretKeyRing) next;
}
} while (true);

View file

@ -32,6 +32,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams;
import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.key.OpenPgpV4Fingerprint;
@ -142,7 +143,7 @@ public class ArmorUtils {
public static String toAsciiArmoredString(InputStream inputStream, MultiMap<String, String> additionalHeaderValues) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ArmoredOutputStream armor = toAsciiArmoredStream(out, additionalHeaderValues);
StreamUtil.pipeAll(inputStream, armor);
Streams.pipeAll(inputStream, armor);
armor.close();
return out.toString();

View file

@ -1,60 +0,0 @@
/*
* Copyright 2021 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.util;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class StreamUtil {
/**
* Pipe all data from the given {@link InputStream} to the given {@link OutputStream}.
*
* This utility method is required, since {@link org.bouncycastle.util.io.Streams#pipeAll(InputStream, OutputStream)}
* internally uses {@link InputStream#read(byte[], int, int)} which silently swallows {@link IOException IOExceptions}.
*
* @see <a href="https://github.com/pgpainless/pgpainless/issues/159#issuecomment-886694555">Explanation</a>
* @see <a href="https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/share/classes/java/io/InputStream.java#L286">
* InputStream swallowing IOExceptions</a>
*
* @param inputStream input stream
* @param outputStream output stream
* @throws IOException io exceptions
*/
public static void pipeAll(InputStream inputStream, OutputStream outputStream) throws IOException {
do {
int i = inputStream.read();
if (i == -1) {
break;
}
outputStream.write(i);
} while (true);
}
/**
* Drain an {@link InputStream} without calling {@link InputStream#read(byte[], int, int)}.
*
* @param inputStream input stream
* @throws IOException io exception
*/
public static void drain(InputStream inputStream) throws IOException {
int i;
do {
i = inputStream.read();
} while (i != -1);
}
}

View file

@ -23,11 +23,11 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.bouncycastle.bcpg.ArmoredInputStream;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.signature.SignatureUtils;
import org.pgpainless.util.ArmoredInputStreamFactory;
import org.pgpainless.util.StreamUtil;
public class WrongArmorChecksumTest {
@ -92,7 +92,7 @@ public class WrongArmorChecksumTest {
assertThrows(IOException.class, () -> {
ArmoredInputStream armorIn = ArmoredInputStreamFactory.get(bytes);
StreamUtil.pipeAll(armorIn, out);
Streams.pipeAll(armorIn, out);
armorIn.close();
});
}

View file

@ -24,11 +24,11 @@ import java.nio.charset.StandardCharsets;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.util.Passphrase;
import org.pgpainless.util.StreamUtil;
public class BrokenAsciiArmorOnMessageDecryptionThrows {
@ -211,7 +211,7 @@ public class BrokenAsciiArmorOnMessageDecryptionThrows {
));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptionStream, outputStream);
Streams.pipeAll(decryptionStream, outputStream);
assertThrows(IOException.class, decryptionStream::close);
}
}

View file

@ -28,13 +28,13 @@ import java.nio.charset.StandardCharsets;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.key.TestKeys;
import org.pgpainless.signature.cleartext_signatures.CleartextSignatureProcessor;
import org.pgpainless.signature.cleartext_signatures.InMemoryMultiPassStrategy;
import org.pgpainless.signature.cleartext_signatures.MultiPassStrategy;
import org.pgpainless.util.StreamUtil;
import org.pgpainless.util.TestUtils;
public class CleartextSignatureVerificationTest {
@ -116,7 +116,7 @@ public class CleartextSignatureVerificationTest {
assertEquals(signature.getKeyID(), signingKeys.getPublicKey().getKeyID());
FileInputStream fileIn = new FileInputStream(file);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
StreamUtil.pipeAll(fileIn, bytes);
Streams.pipeAll(fileIn, bytes);
fileIn.close();
assertArrayEquals(message.getBytes(StandardCharsets.UTF_8), bytes.toByteArray());
}

View file

@ -26,6 +26,7 @@ import java.nio.charset.Charset;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@ -36,7 +37,6 @@ import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.TestKeys;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.util.StreamUtil;
public class DecryptAndVerifyMessageTest {
@ -67,7 +67,7 @@ public class DecryptAndVerifyMessageTest {
.withOptions(options);
ByteArrayOutputStream toPlain = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptor, toPlain);
Streams.pipeAll(decryptor, toPlain);
decryptor.close();
toPlain.close();
OpenPgpMetadata metadata = decryptor.getResult();

View file

@ -26,6 +26,7 @@ import java.util.List;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.pgpainless.PGPainless;
@ -33,7 +34,6 @@ import org.pgpainless.algorithm.EncryptionPurpose;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.util.StreamUtil;
public class DecryptHiddenRecipientMessage {
@ -148,7 +148,7 @@ public class DecryptHiddenRecipientMessage {
.withOptions(options);
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptionStream, out);
Streams.pipeAll(decryptionStream, out);
decryptionStream.close();
OpenPgpMetadata metadata = decryptionStream.getResult();

View file

@ -28,6 +28,7 @@ import java.util.Collections;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@ -37,7 +38,6 @@ import org.pgpainless.exception.ModificationDetectionException;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.util.Passphrase;
import org.pgpainless.util.StreamUtil;
public class ModificationDetectionTests {
@ -160,7 +160,7 @@ public class ModificationDetectionTests {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
assertThrows(EOFException.class, () -> {
StreamUtil.pipeAll(decryptionStream, outputStream);
Streams.pipeAll(decryptionStream, outputStream);
decryptionStream.close();
});
}
@ -192,7 +192,7 @@ public class ModificationDetectionTests {
);
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptionStream, out);
Streams.pipeAll(decryptionStream, out);
assertThrows(ModificationDetectionException.class, decryptionStream::close);
}
@ -223,7 +223,7 @@ public class ModificationDetectionTests {
);
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptionStream, out);
Streams.pipeAll(decryptionStream, out);
assertThrows(ModificationDetectionException.class, decryptionStream::close);
}

View file

@ -24,11 +24,11 @@ import java.nio.charset.StandardCharsets;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.pgpainless.PGPainless;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.util.StreamUtil;
public class RecursionDepthTest {
@ -160,7 +160,7 @@ public class RecursionDepthTest {
.withOptions(new ConsumerOptions().addDecryptionKey(secretKey));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptionStream, outputStream);
Streams.pipeAll(decryptionStream, outputStream);
});
}

View file

@ -32,6 +32,7 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType;
@ -42,7 +43,6 @@ import org.pgpainless.key.TestKeys;
import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.util.StreamUtil;
/**
* Test functionality of the {@link MissingPublicKeyCallback} which is called when during signature verification,
@ -66,7 +66,7 @@ public class VerifyWithMissingPublicKeyCallback {
SecretKeyRingProtector.unprotectedKeys(),
signingSecKeys, DocumentSignatureType.CANONICAL_TEXT_DOCUMENT
)));
StreamUtil.pipeAll(new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8)), signingStream);
Streams.pipeAll(new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8)), signingStream);
signingStream.close();
DecryptionStream verificationStream = PGPainless.decryptAndOrVerify()
@ -83,7 +83,7 @@ public class VerifyWithMissingPublicKeyCallback {
}));
ByteArrayOutputStream plainOut = new ByteArrayOutputStream();
StreamUtil.pipeAll(verificationStream, plainOut);
Streams.pipeAll(verificationStream, plainOut);
verificationStream.close();
assertArrayEquals(msg.getBytes(StandardCharsets.UTF_8), plainOut.toByteArray());

View file

@ -34,6 +34,7 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@ -58,7 +59,6 @@ import org.pgpainless.key.protection.UnprotectedKeysProtector;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.policy.Policy;
import org.pgpainless.util.ArmoredOutputStreamFactory;
import org.pgpainless.util.StreamUtil;
public class EncryptDecryptTest {
@ -168,7 +168,7 @@ public class EncryptDecryptTest {
new SigningOptions().addInlineSignature(keyDecryptor, senderSec, DocumentSignatureType.BINARY_DOCUMENT)
));
StreamUtil.pipeAll(new ByteArrayInputStream(secretMessage), encryptor);
Streams.pipeAll(new ByteArrayInputStream(secretMessage), encryptor);
encryptor.close();
byte[] encryptedSecretMessage = envelope.toByteArray();
@ -193,7 +193,7 @@ public class EncryptDecryptTest {
ByteArrayOutputStream decryptedSecretMessage = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptor, decryptedSecretMessage);
Streams.pipeAll(decryptor, decryptedSecretMessage);
decryptor.close();
assertArrayEquals(secretMessage, decryptedSecretMessage.toByteArray());
@ -218,7 +218,7 @@ public class EncryptDecryptTest {
.withOptions(ProducerOptions.sign(
new SigningOptions().addDetachedSignature(keyRingProtector, signingKeys, DocumentSignatureType.BINARY_DOCUMENT)
));
StreamUtil.pipeAll(inputStream, signer);
Streams.pipeAll(inputStream, signer);
signer.close();
EncryptionResult metadata = signer.getResult();
@ -243,7 +243,7 @@ public class EncryptDecryptTest {
);
dummyOut = new ByteArrayOutputStream();
StreamUtil.pipeAll(verifier, dummyOut);
Streams.pipeAll(verifier, dummyOut);
verifier.close();
OpenPgpMetadata decryptionResult = verifier.getResult();
@ -264,7 +264,7 @@ public class EncryptDecryptTest {
SigningOptions.get()
.addInlineSignature(keyRingProtector, signingKeys, DocumentSignatureType.BINARY_DOCUMENT)
).setAsciiArmor(true));
StreamUtil.pipeAll(inputStream, signer);
Streams.pipeAll(inputStream, signer);
signer.close();
inputStream = new ByteArrayInputStream(signOut.toByteArray());
@ -274,7 +274,7 @@ public class EncryptDecryptTest {
.addVerificationCert(KeyRingUtils.publicKeyRingFrom(signingKeys))
);
signOut = new ByteArrayOutputStream();
StreamUtil.pipeAll(verifier, signOut);
Streams.pipeAll(verifier, signOut);
verifier.close();
OpenPgpMetadata metadata = verifier.getResult();

View file

@ -31,6 +31,7 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPLiteralData;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
import org.junit.JUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@ -39,7 +40,6 @@ import org.pgpainless.algorithm.StreamEncoding;
import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata;
import org.pgpainless.util.StreamUtil;
public class FileInformationTest {
@ -72,7 +72,7 @@ public class FileInformationTest {
.setEncoding(encoding)
);
StreamUtil.pipeAll(dataIn, encryptionStream);
Streams.pipeAll(dataIn, encryptionStream);
encryptionStream.close();
EncryptionResult encResult = encryptionStream.getResult();
@ -87,7 +87,7 @@ public class FileInformationTest {
.onInputStream(cryptIn)
.withOptions(new ConsumerOptions()
.addDecryptionKey(secretKey));
StreamUtil.pipeAll(decryptionStream, plainOut);
Streams.pipeAll(decryptionStream, plainOut);
decryptionStream.close();
@ -110,7 +110,7 @@ public class FileInformationTest {
.addRecipient(certificate))
);
StreamUtil.pipeAll(dataIn, encryptionStream);
Streams.pipeAll(dataIn, encryptionStream);
encryptionStream.close();
EncryptionResult encResult = encryptionStream.getResult();
@ -126,7 +126,7 @@ public class FileInformationTest {
.onInputStream(cryptIn)
.withOptions(new ConsumerOptions()
.addDecryptionKey(secretKey));
StreamUtil.pipeAll(decryptionStream, plainOut);
Streams.pipeAll(decryptionStream, plainOut);
decryptionStream.close();
@ -151,7 +151,7 @@ public class FileInformationTest {
.setForYourEyesOnly()
);
StreamUtil.pipeAll(dataIn, encryptionStream);
Streams.pipeAll(dataIn, encryptionStream);
encryptionStream.close();
EncryptionResult encResult = encryptionStream.getResult();
@ -167,7 +167,7 @@ public class FileInformationTest {
.onInputStream(cryptIn)
.withOptions(new ConsumerOptions()
.addDecryptionKey(secretKey));
StreamUtil.pipeAll(decryptionStream, plainOut);
Streams.pipeAll(decryptionStream, plainOut);
decryptionStream.close();

View file

@ -33,6 +33,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@ -48,7 +49,6 @@ import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.util.Passphrase;
import org.pgpainless.util.StreamUtil;
public class SigningTest {
@ -81,7 +81,7 @@ public class SigningTest {
byte[] messageBytes = "This message is signed and encrypted to Romeo and Juliet.".getBytes(StandardCharsets.UTF_8);
ByteArrayInputStream message = new ByteArrayInputStream(messageBytes);
StreamUtil.pipeAll(message, encryptionStream);
Streams.pipeAll(message, encryptionStream);
encryptionStream.close();
byte[] encrypted = out.toByteArray();
@ -102,7 +102,7 @@ public class SigningTest {
ByteArrayOutputStream plaintextOut = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptionStream, plaintextOut);
Streams.pipeAll(decryptionStream, plaintextOut);
decryptionStream.close();
OpenPgpMetadata metadata = decryptionStream.getResult();

View file

@ -28,6 +28,7 @@ import java.security.NoSuchAlgorithmException;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType;
@ -41,7 +42,6 @@ import org.pgpainless.encryption_signing.SigningOptions;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.util.Passphrase;
import org.pgpainless.util.StreamUtil;
public class Encrypt {
@ -82,7 +82,7 @@ public class Encrypt {
);
// Pipe data trough and CLOSE the stream (important)
StreamUtil.pipeAll(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)), encryptor);
Streams.pipeAll(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)), encryptor);
encryptor.close();
String encryptedMessage = ciphertext.toString();
@ -96,7 +96,7 @@ public class Encrypt {
ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptor, plaintext);
Streams.pipeAll(decryptor, plaintext);
decryptor.close();
// Check the metadata to see how the message was encrypted/signed
@ -126,7 +126,7 @@ public class Encrypt {
).setAsciiArmor(true)
);
StreamUtil.pipeAll(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)), encryptor);
Streams.pipeAll(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)), encryptor);
encryptor.close();
String asciiCiphertext = ciphertext.toString();
@ -137,7 +137,7 @@ public class Encrypt {
.withOptions(new ConsumerOptions().addDecryptionPassphrase(Passphrase.fromPassword("p4ssphr4s3")));
ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptor, plaintext);
Streams.pipeAll(decryptor, plaintext);
decryptor.close();

View file

@ -33,6 +33,7 @@ import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider;
import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder;
import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.pgpainless.PGPainless;
@ -46,7 +47,6 @@ import org.pgpainless.key.protection.KeyRingProtectionSettings;
import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
import org.pgpainless.key.protection.UnlockSecretKey;
import org.pgpainless.util.Passphrase;
import org.pgpainless.util.StreamUtil;
public class ChangeSecretKeyRingPassphraseTest {
@ -199,7 +199,7 @@ public class ChangeSecretKeyRingPassphraseTest {
.addInlineSignature(PasswordBasedSecretKeyRingProtector.forKey(keyRing, passphrase),
keyRing, DocumentSignatureType.BINARY_DOCUMENT)));
StreamUtil.pipeAll(new ByteArrayInputStream(dummyMessage.getBytes()), stream);
Streams.pipeAll(new ByteArrayInputStream(dummyMessage.getBytes()), stream);
stream.close();
}
}

View file

@ -30,6 +30,7 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.decryption_verification.ConsumerOptions;
@ -37,7 +38,6 @@ import org.pgpainless.decryption_verification.DecryptionStream;
import org.pgpainless.decryption_verification.OpenPgpMetadata;
import org.pgpainless.key.OpenPgpV4Fingerprint;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.util.StreamUtil;
/**
* Test if marker packets are being ignored properly.
@ -162,7 +162,7 @@ public class IgnoreMarkerPackets {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptionStream, outputStream);
Streams.pipeAll(decryptionStream, outputStream);
decryptionStream.close();
OpenPgpMetadata metadata = decryptionStream.getResult();
@ -211,7 +211,7 @@ public class IgnoreMarkerPackets {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptionStream, outputStream);
Streams.pipeAll(decryptionStream, outputStream);
decryptionStream.close();
assertArrayEquals(data.getBytes(StandardCharsets.UTF_8), outputStream.toByteArray());

View file

@ -21,6 +21,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.pgpainless.PGPainless;
@ -31,7 +32,6 @@ import org.pgpainless.encryption_signing.EncryptionStream;
import org.pgpainless.encryption_signing.ProducerOptions;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.util.Passphrase;
import org.pgpainless.util.StreamUtil;
public class MultiPassphraseSymmetricEncryptionTest {
@ -51,7 +51,7 @@ public class MultiPassphraseSymmetricEncryptionTest {
.addPassphrase(Passphrase.fromPassword("p2"))
).setAsciiArmor(false));
StreamUtil.pipeAll(plaintextIn, encryptor);
Streams.pipeAll(plaintextIn, encryptor);
encryptor.close();
byte[] ciphertext = ciphertextOut.toByteArray();
@ -65,7 +65,7 @@ public class MultiPassphraseSymmetricEncryptionTest {
ByteArrayOutputStream plaintextOut = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptor, plaintextOut);
Streams.pipeAll(decryptor, plaintextOut);
decryptor.close();
}

View file

@ -27,6 +27,7 @@ import java.util.Random;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.pgpainless.PGPainless;
@ -43,7 +44,6 @@ import org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.passphrase_provider.SolitaryPassphraseProvider;
import org.pgpainless.util.Passphrase;
import org.pgpainless.util.StreamUtil;
/**
* Test parallel symmetric and public key encryption/decryption.
@ -68,7 +68,7 @@ public class SymmetricEncryptionTest {
.addRecipient(encryptionKey)
));
StreamUtil.pipeAll(plaintextIn, encryptor);
Streams.pipeAll(plaintextIn, encryptor);
encryptor.close();
byte[] ciphertext = ciphertextOut.toByteArray();
@ -81,7 +81,7 @@ public class SymmetricEncryptionTest {
ByteArrayOutputStream decrypted = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptor, decrypted);
Streams.pipeAll(decryptor, decrypted);
decryptor.close();
assertArrayEquals(plaintext, decrypted.toByteArray());
@ -98,7 +98,7 @@ public class SymmetricEncryptionTest {
decrypted = new ByteArrayOutputStream();
StreamUtil.pipeAll(decryptor, decrypted);
Streams.pipeAll(decryptor, decrypted);
decryptor.close();
assertArrayEquals(plaintext, decrypted.toByteArray());
@ -118,7 +118,7 @@ public class SymmetricEncryptionTest {
EncryptionOptions.encryptCommunications()
.addPassphrase(Passphrase.fromPassword("mellon"))));
StreamUtil.pipeAll(new ByteArrayInputStream(bytes), encryptor);
Streams.pipeAll(new ByteArrayInputStream(bytes), encryptor);
encryptor.close();
assertThrows(MissingDecryptionMethodException.class, () -> PGPainless.decryptAndOrVerify()

View file

@ -25,6 +25,7 @@ import java.nio.charset.StandardCharsets;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.Test;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.EncryptionPurpose;
@ -34,7 +35,6 @@ import org.pgpainless.encryption_signing.EncryptionStream;
import org.pgpainless.encryption_signing.ProducerOptions;
import org.pgpainless.key.WeirdKeys;
import org.pgpainless.key.util.KeyRingUtils;
import org.pgpainless.util.StreamUtil;
public class TestTwoSubkeysEncryption {
@ -68,7 +68,7 @@ public class TestTwoSubkeysEncryption {
.setAsciiArmor(false)
);
StreamUtil.pipeAll(getPlainIn(), encryptionStream);
Streams.pipeAll(getPlainIn(), encryptionStream);
encryptionStream.close();
EncryptionResult metadata = encryptionStream.getResult();

View file

@ -23,8 +23,8 @@ import java.nio.charset.Charset;
import java.util.Arrays;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.util.io.Streams;
import org.pgpainless.util.ArmoredOutputStreamFactory;
import org.pgpainless.util.StreamUtil;
import sop.Ready;
import sop.enums.ArmorLabel;
import sop.exception.SOPGPException;
@ -57,10 +57,10 @@ public class ArmorImpl implements Armor {
int read = pbIn.read(buffer);
pbIn.unread(buffer, 0, read);
if (!allowNested && Arrays.equals(ARMOR_START, buffer)) {
StreamUtil.pipeAll(pbIn, System.out);
Streams.pipeAll(pbIn, System.out);
} else {
ArmoredOutputStream armor = ArmoredOutputStreamFactory.get(System.out);
StreamUtil.pipeAll(pbIn, armor);
Streams.pipeAll(pbIn, armor);
armor.close();
}
}

View file

@ -20,7 +20,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import org.bouncycastle.openpgp.PGPUtil;
import org.pgpainless.util.StreamUtil;
import org.bouncycastle.util.io.Streams;
import sop.Ready;
import sop.operation.Dearmor;
@ -32,7 +32,7 @@ public class DearmorImpl implements Dearmor {
return new Ready() {
@Override
public void writeTo(OutputStream outputStream) throws IOException {
StreamUtil.pipeAll(decoder, outputStream);
Streams.pipeAll(decoder, outputStream);
decoder.close();
}
};

View file

@ -27,6 +27,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.util.io.Streams;
import org.pgpainless.PGPainless;
import org.pgpainless.decryption_verification.ConsumerOptions;
import org.pgpainless.decryption_verification.DecryptionStream;
@ -36,7 +37,6 @@ import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.util.Passphrase;
import org.pgpainless.util.StreamUtil;
import sop.DecryptionResult;
import sop.ReadyWithResult;
import sop.SessionKey;
@ -151,7 +151,7 @@ public class DecryptImpl implements Decrypt {
return new ReadyWithResult<DecryptionResult>() {
@Override
public DecryptionResult writeTo(OutputStream outputStream) throws IOException, SOPGPException.NoSignature {
StreamUtil.pipeAll(decryptionStream, outputStream);
Streams.pipeAll(decryptionStream, outputStream);
decryptionStream.close();
OpenPgpMetadata metadata = decryptionStream.getResult();

View file

@ -22,6 +22,7 @@ import java.io.OutputStream;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.algorithm.StreamEncoding;
@ -32,12 +33,11 @@ import org.pgpainless.encryption_signing.SigningOptions;
import org.pgpainless.exception.WrongPassphraseException;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.util.Passphrase;
import org.pgpainless.util.StreamUtil;
import sop.util.ProxyOutputStream;
import sop.Ready;
import sop.enums.EncryptAs;
import sop.exception.SOPGPException;
import sop.operation.Encrypt;
import sop.util.ProxyOutputStream;
public class EncryptImpl implements Encrypt {
@ -117,7 +117,7 @@ public class EncryptImpl implements Encrypt {
@Override
public void writeTo(OutputStream outputStream) throws IOException {
proxy.replaceOutputStream(outputStream);
StreamUtil.pipeAll(plaintext, encryptionStream);
Streams.pipeAll(plaintext, encryptionStream);
encryptionStream.close();
}
};

View file

@ -25,6 +25,7 @@ import java.util.List;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
import org.bouncycastle.util.io.Streams;
import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.DocumentSignatureType;
import org.pgpainless.encryption_signing.EncryptionResult;
@ -35,7 +36,6 @@ import org.pgpainless.key.SubkeyIdentifier;
import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.util.ArmoredOutputStreamFactory;
import org.pgpainless.util.StreamUtil;
import sop.Ready;
import sop.enums.SignAs;
import sop.exception.SOPGPException;
@ -92,7 +92,7 @@ public class SignImpl implements Sign {
throw new IllegalStateException("EncryptionStream is already closed.");
}
StreamUtil.pipeAll(data, signingStream);
Streams.pipeAll(data, signingStream);
signingStream.close();
EncryptionResult encryptionResult = signingStream.getResult();