mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-29 15:52:08 +01:00
Revert introduction of StreamUtil
This commit is contained in:
parent
b8f719d3eb
commit
311c842196
27 changed files with 78 additions and 137 deletions
|
@ -127,7 +127,7 @@ Still it allows you to manually specify which algorithms to use of course.
|
||||||
).setAsciiArmor(true) // Ascii armor or not
|
).setAsciiArmor(true) // Ascii armor or not
|
||||||
);
|
);
|
||||||
|
|
||||||
StreamUtil.pipeAll(plaintextInputStream, encryptionStream);
|
Streams.pipeAll(plaintextInputStream, encryptionStream);
|
||||||
encryptionStream.close();
|
encryptionStream.close();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ This behaviour can be modified though using the `Policy` class.
|
||||||
.addVerificationCert(alicePubKeys)
|
.addVerificationCert(alicePubKeys)
|
||||||
);
|
);
|
||||||
|
|
||||||
StreamUtil.pipeAll(decryptionStream, outputStream);
|
Streams.pipeAll(decryptionStream, outputStream);
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
|
|
||||||
// Result contains information like signature status etc.
|
// Result contains information like signature status etc.
|
||||||
|
|
|
@ -36,6 +36,7 @@ import com.ginsberg.junit.exit.FailOnSystemExit;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.AfterAll;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -45,7 +46,6 @@ import org.pgpainless.cli.TestUtils;
|
||||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||||
import org.pgpainless.key.info.KeyRingInfo;
|
import org.pgpainless.key.info.KeyRingInfo;
|
||||||
import org.pgpainless.key.util.KeyRingUtils;
|
import org.pgpainless.key.util.KeyRingUtils;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class SignVerifyTest {
|
public class SignVerifyTest {
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public class SignVerifyTest {
|
||||||
PGPSecretKeyRing aliceKeys = PGPainless.generateKeyRing()
|
PGPSecretKeyRing aliceKeys = PGPainless.generateKeyRing()
|
||||||
.modernKeyRing("alice", null);
|
.modernKeyRing("alice", null);
|
||||||
OutputStream aliceKeyOut = new FileOutputStream(aliceKeyFile);
|
OutputStream aliceKeyOut = new FileOutputStream(aliceKeyFile);
|
||||||
StreamUtil.pipeAll(new ByteArrayInputStream(aliceKeys.getEncoded()), aliceKeyOut);
|
Streams.pipeAll(new ByteArrayInputStream(aliceKeys.getEncoded()), aliceKeyOut);
|
||||||
aliceKeyOut.close();
|
aliceKeyOut.close();
|
||||||
|
|
||||||
// Write alice pub key to disc
|
// Write alice pub key to disc
|
||||||
|
@ -79,14 +79,14 @@ public class SignVerifyTest {
|
||||||
assertTrue(aliceCertFile.createNewFile());
|
assertTrue(aliceCertFile.createNewFile());
|
||||||
PGPPublicKeyRing alicePub = KeyRingUtils.publicKeyRingFrom(aliceKeys);
|
PGPPublicKeyRing alicePub = KeyRingUtils.publicKeyRingFrom(aliceKeys);
|
||||||
OutputStream aliceCertOut = new FileOutputStream(aliceCertFile);
|
OutputStream aliceCertOut = new FileOutputStream(aliceCertFile);
|
||||||
StreamUtil.pipeAll(new ByteArrayInputStream(alicePub.getEncoded()), aliceCertOut);
|
Streams.pipeAll(new ByteArrayInputStream(alicePub.getEncoded()), aliceCertOut);
|
||||||
aliceCertOut.close();
|
aliceCertOut.close();
|
||||||
|
|
||||||
// Write test data to disc
|
// Write test data to disc
|
||||||
File dataFile = new File(tempDir, "data");
|
File dataFile = new File(tempDir, "data");
|
||||||
assertTrue(dataFile.createNewFile());
|
assertTrue(dataFile.createNewFile());
|
||||||
FileOutputStream dataOut = new FileOutputStream(dataFile);
|
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();
|
dataOut.close();
|
||||||
|
|
||||||
// Sign test data
|
// Sign test data
|
||||||
|
|
|
@ -35,10 +35,10 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||||
import org.bouncycastle.openpgp.PGPUtil;
|
import org.bouncycastle.openpgp.PGPUtil;
|
||||||
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
|
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.pgpainless.implementation.ImplementationFactory;
|
import org.pgpainless.implementation.ImplementationFactory;
|
||||||
import org.pgpainless.key.collection.PGPKeyRingCollection;
|
import org.pgpainless.key.collection.PGPKeyRingCollection;
|
||||||
import org.pgpainless.util.ArmoredInputStreamFactory;
|
import org.pgpainless.util.ArmoredInputStreamFactory;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class KeyRingReader {
|
public class KeyRingReader {
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ public class KeyRingReader {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (next instanceof PGPSecretKeyRing) {
|
if (next instanceof PGPSecretKeyRing) {
|
||||||
StreamUtil.drain(decoderStream);
|
Streams.drain(decoderStream);
|
||||||
return (PGPSecretKeyRing) next;
|
return (PGPSecretKeyRing) next;
|
||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.pgpainless.algorithm.HashAlgorithm;
|
import org.pgpainless.algorithm.HashAlgorithm;
|
||||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||||
|
|
||||||
|
@ -142,7 +143,7 @@ public class ArmorUtils {
|
||||||
public static String toAsciiArmoredString(InputStream inputStream, MultiMap<String, String> additionalHeaderValues) throws IOException {
|
public static String toAsciiArmoredString(InputStream inputStream, MultiMap<String, String> additionalHeaderValues) throws IOException {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ArmoredOutputStream armor = toAsciiArmoredStream(out, additionalHeaderValues);
|
ArmoredOutputStream armor = toAsciiArmoredStream(out, additionalHeaderValues);
|
||||||
StreamUtil.pipeAll(inputStream, armor);
|
Streams.pipeAll(inputStream, armor);
|
||||||
armor.close();
|
armor.close();
|
||||||
|
|
||||||
return out.toString();
|
return out.toString();
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -23,11 +23,11 @@ import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.bouncycastle.bcpg.ArmoredInputStream;
|
import org.bouncycastle.bcpg.ArmoredInputStream;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.signature.SignatureUtils;
|
import org.pgpainless.signature.SignatureUtils;
|
||||||
import org.pgpainless.util.ArmoredInputStreamFactory;
|
import org.pgpainless.util.ArmoredInputStreamFactory;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class WrongArmorChecksumTest {
|
public class WrongArmorChecksumTest {
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ public class WrongArmorChecksumTest {
|
||||||
|
|
||||||
assertThrows(IOException.class, () -> {
|
assertThrows(IOException.class, () -> {
|
||||||
ArmoredInputStream armorIn = ArmoredInputStreamFactory.get(bytes);
|
ArmoredInputStream armorIn = ArmoredInputStreamFactory.get(bytes);
|
||||||
StreamUtil.pipeAll(armorIn, out);
|
Streams.pipeAll(armorIn, out);
|
||||||
armorIn.close();
|
armorIn.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,11 @@ import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class BrokenAsciiArmorOnMessageDecryptionThrows {
|
public class BrokenAsciiArmorOnMessageDecryptionThrows {
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ public class BrokenAsciiArmorOnMessageDecryptionThrows {
|
||||||
));
|
));
|
||||||
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
StreamUtil.pipeAll(decryptionStream, outputStream);
|
Streams.pipeAll(decryptionStream, outputStream);
|
||||||
assertThrows(IOException.class, decryptionStream::close);
|
assertThrows(IOException.class, decryptionStream::close);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,13 @@ import java.nio.charset.StandardCharsets;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSignature;
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.key.TestKeys;
|
import org.pgpainless.key.TestKeys;
|
||||||
import org.pgpainless.signature.cleartext_signatures.CleartextSignatureProcessor;
|
import org.pgpainless.signature.cleartext_signatures.CleartextSignatureProcessor;
|
||||||
import org.pgpainless.signature.cleartext_signatures.InMemoryMultiPassStrategy;
|
import org.pgpainless.signature.cleartext_signatures.InMemoryMultiPassStrategy;
|
||||||
import org.pgpainless.signature.cleartext_signatures.MultiPassStrategy;
|
import org.pgpainless.signature.cleartext_signatures.MultiPassStrategy;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
import org.pgpainless.util.TestUtils;
|
import org.pgpainless.util.TestUtils;
|
||||||
|
|
||||||
public class CleartextSignatureVerificationTest {
|
public class CleartextSignatureVerificationTest {
|
||||||
|
@ -116,7 +116,7 @@ public class CleartextSignatureVerificationTest {
|
||||||
assertEquals(signature.getKeyID(), signingKeys.getPublicKey().getKeyID());
|
assertEquals(signature.getKeyID(), signingKeys.getPublicKey().getKeyID());
|
||||||
FileInputStream fileIn = new FileInputStream(file);
|
FileInputStream fileIn = new FileInputStream(file);
|
||||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||||
StreamUtil.pipeAll(fileIn, bytes);
|
Streams.pipeAll(fileIn, bytes);
|
||||||
fileIn.close();
|
fileIn.close();
|
||||||
assertArrayEquals(message.getBytes(StandardCharsets.UTF_8), bytes.toByteArray());
|
assertArrayEquals(message.getBytes(StandardCharsets.UTF_8), bytes.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.nio.charset.Charset;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
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.SubkeyIdentifier;
|
||||||
import org.pgpainless.key.TestKeys;
|
import org.pgpainless.key.TestKeys;
|
||||||
import org.pgpainless.key.util.KeyRingUtils;
|
import org.pgpainless.key.util.KeyRingUtils;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class DecryptAndVerifyMessageTest {
|
public class DecryptAndVerifyMessageTest {
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class DecryptAndVerifyMessageTest {
|
||||||
.withOptions(options);
|
.withOptions(options);
|
||||||
|
|
||||||
ByteArrayOutputStream toPlain = new ByteArrayOutputStream();
|
ByteArrayOutputStream toPlain = new ByteArrayOutputStream();
|
||||||
StreamUtil.pipeAll(decryptor, toPlain);
|
Streams.pipeAll(decryptor, toPlain);
|
||||||
decryptor.close();
|
decryptor.close();
|
||||||
toPlain.close();
|
toPlain.close();
|
||||||
OpenPgpMetadata metadata = decryptor.getResult();
|
OpenPgpMetadata metadata = decryptor.getResult();
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.util.List;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
|
@ -33,7 +34,6 @@ import org.pgpainless.algorithm.EncryptionPurpose;
|
||||||
import org.pgpainless.implementation.ImplementationFactory;
|
import org.pgpainless.implementation.ImplementationFactory;
|
||||||
import org.pgpainless.key.SubkeyIdentifier;
|
import org.pgpainless.key.SubkeyIdentifier;
|
||||||
import org.pgpainless.key.info.KeyRingInfo;
|
import org.pgpainless.key.info.KeyRingInfo;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class DecryptHiddenRecipientMessage {
|
public class DecryptHiddenRecipientMessage {
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ public class DecryptHiddenRecipientMessage {
|
||||||
.withOptions(options);
|
.withOptions(options);
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
StreamUtil.pipeAll(decryptionStream, out);
|
Streams.pipeAll(decryptionStream, out);
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
|
|
||||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.util.Collections;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
@ -37,7 +38,6 @@ import org.pgpainless.exception.ModificationDetectionException;
|
||||||
import org.pgpainless.implementation.ImplementationFactory;
|
import org.pgpainless.implementation.ImplementationFactory;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class ModificationDetectionTests {
|
public class ModificationDetectionTests {
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ public class ModificationDetectionTests {
|
||||||
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
assertThrows(EOFException.class, () -> {
|
assertThrows(EOFException.class, () -> {
|
||||||
StreamUtil.pipeAll(decryptionStream, outputStream);
|
Streams.pipeAll(decryptionStream, outputStream);
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ public class ModificationDetectionTests {
|
||||||
);
|
);
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
StreamUtil.pipeAll(decryptionStream, out);
|
Streams.pipeAll(decryptionStream, out);
|
||||||
assertThrows(ModificationDetectionException.class, decryptionStream::close);
|
assertThrows(ModificationDetectionException.class, decryptionStream::close);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ public class ModificationDetectionTests {
|
||||||
);
|
);
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
StreamUtil.pipeAll(decryptionStream, out);
|
Streams.pipeAll(decryptionStream, out);
|
||||||
assertThrows(ModificationDetectionException.class, decryptionStream::close);
|
assertThrows(ModificationDetectionException.class, decryptionStream::close);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,11 @@ import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.implementation.ImplementationFactory;
|
import org.pgpainless.implementation.ImplementationFactory;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class RecursionDepthTest {
|
public class RecursionDepthTest {
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ public class RecursionDepthTest {
|
||||||
.withOptions(new ConsumerOptions().addDecryptionKey(secretKey));
|
.withOptions(new ConsumerOptions().addDecryptionKey(secretKey));
|
||||||
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
StreamUtil.pipeAll(decryptionStream, outputStream);
|
Streams.pipeAll(decryptionStream, outputStream);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.algorithm.DocumentSignatureType;
|
import org.pgpainless.algorithm.DocumentSignatureType;
|
||||||
|
@ -42,7 +43,6 @@ import org.pgpainless.key.TestKeys;
|
||||||
import org.pgpainless.key.info.KeyRingInfo;
|
import org.pgpainless.key.info.KeyRingInfo;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.key.util.KeyRingUtils;
|
import org.pgpainless.key.util.KeyRingUtils;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test functionality of the {@link MissingPublicKeyCallback} which is called when during signature verification,
|
* Test functionality of the {@link MissingPublicKeyCallback} which is called when during signature verification,
|
||||||
|
@ -66,7 +66,7 @@ public class VerifyWithMissingPublicKeyCallback {
|
||||||
SecretKeyRingProtector.unprotectedKeys(),
|
SecretKeyRingProtector.unprotectedKeys(),
|
||||||
signingSecKeys, DocumentSignatureType.CANONICAL_TEXT_DOCUMENT
|
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();
|
signingStream.close();
|
||||||
|
|
||||||
DecryptionStream verificationStream = PGPainless.decryptAndOrVerify()
|
DecryptionStream verificationStream = PGPainless.decryptAndOrVerify()
|
||||||
|
@ -83,7 +83,7 @@ public class VerifyWithMissingPublicKeyCallback {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
ByteArrayOutputStream plainOut = new ByteArrayOutputStream();
|
ByteArrayOutputStream plainOut = new ByteArrayOutputStream();
|
||||||
StreamUtil.pipeAll(verificationStream, plainOut);
|
Streams.pipeAll(verificationStream, plainOut);
|
||||||
verificationStream.close();
|
verificationStream.close();
|
||||||
|
|
||||||
assertArrayEquals(msg.getBytes(StandardCharsets.UTF_8), plainOut.toByteArray());
|
assertArrayEquals(msg.getBytes(StandardCharsets.UTF_8), plainOut.toByteArray());
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSignature;
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
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.key.util.KeyRingUtils;
|
||||||
import org.pgpainless.policy.Policy;
|
import org.pgpainless.policy.Policy;
|
||||||
import org.pgpainless.util.ArmoredOutputStreamFactory;
|
import org.pgpainless.util.ArmoredOutputStreamFactory;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class EncryptDecryptTest {
|
public class EncryptDecryptTest {
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ public class EncryptDecryptTest {
|
||||||
new SigningOptions().addInlineSignature(keyDecryptor, senderSec, DocumentSignatureType.BINARY_DOCUMENT)
|
new SigningOptions().addInlineSignature(keyDecryptor, senderSec, DocumentSignatureType.BINARY_DOCUMENT)
|
||||||
));
|
));
|
||||||
|
|
||||||
StreamUtil.pipeAll(new ByteArrayInputStream(secretMessage), encryptor);
|
Streams.pipeAll(new ByteArrayInputStream(secretMessage), encryptor);
|
||||||
encryptor.close();
|
encryptor.close();
|
||||||
byte[] encryptedSecretMessage = envelope.toByteArray();
|
byte[] encryptedSecretMessage = envelope.toByteArray();
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ public class EncryptDecryptTest {
|
||||||
|
|
||||||
ByteArrayOutputStream decryptedSecretMessage = new ByteArrayOutputStream();
|
ByteArrayOutputStream decryptedSecretMessage = new ByteArrayOutputStream();
|
||||||
|
|
||||||
StreamUtil.pipeAll(decryptor, decryptedSecretMessage);
|
Streams.pipeAll(decryptor, decryptedSecretMessage);
|
||||||
decryptor.close();
|
decryptor.close();
|
||||||
|
|
||||||
assertArrayEquals(secretMessage, decryptedSecretMessage.toByteArray());
|
assertArrayEquals(secretMessage, decryptedSecretMessage.toByteArray());
|
||||||
|
@ -218,7 +218,7 @@ public class EncryptDecryptTest {
|
||||||
.withOptions(ProducerOptions.sign(
|
.withOptions(ProducerOptions.sign(
|
||||||
new SigningOptions().addDetachedSignature(keyRingProtector, signingKeys, DocumentSignatureType.BINARY_DOCUMENT)
|
new SigningOptions().addDetachedSignature(keyRingProtector, signingKeys, DocumentSignatureType.BINARY_DOCUMENT)
|
||||||
));
|
));
|
||||||
StreamUtil.pipeAll(inputStream, signer);
|
Streams.pipeAll(inputStream, signer);
|
||||||
signer.close();
|
signer.close();
|
||||||
|
|
||||||
EncryptionResult metadata = signer.getResult();
|
EncryptionResult metadata = signer.getResult();
|
||||||
|
@ -243,7 +243,7 @@ public class EncryptDecryptTest {
|
||||||
);
|
);
|
||||||
|
|
||||||
dummyOut = new ByteArrayOutputStream();
|
dummyOut = new ByteArrayOutputStream();
|
||||||
StreamUtil.pipeAll(verifier, dummyOut);
|
Streams.pipeAll(verifier, dummyOut);
|
||||||
verifier.close();
|
verifier.close();
|
||||||
|
|
||||||
OpenPgpMetadata decryptionResult = verifier.getResult();
|
OpenPgpMetadata decryptionResult = verifier.getResult();
|
||||||
|
@ -264,7 +264,7 @@ public class EncryptDecryptTest {
|
||||||
SigningOptions.get()
|
SigningOptions.get()
|
||||||
.addInlineSignature(keyRingProtector, signingKeys, DocumentSignatureType.BINARY_DOCUMENT)
|
.addInlineSignature(keyRingProtector, signingKeys, DocumentSignatureType.BINARY_DOCUMENT)
|
||||||
).setAsciiArmor(true));
|
).setAsciiArmor(true));
|
||||||
StreamUtil.pipeAll(inputStream, signer);
|
Streams.pipeAll(inputStream, signer);
|
||||||
signer.close();
|
signer.close();
|
||||||
|
|
||||||
inputStream = new ByteArrayInputStream(signOut.toByteArray());
|
inputStream = new ByteArrayInputStream(signOut.toByteArray());
|
||||||
|
@ -274,7 +274,7 @@ public class EncryptDecryptTest {
|
||||||
.addVerificationCert(KeyRingUtils.publicKeyRingFrom(signingKeys))
|
.addVerificationCert(KeyRingUtils.publicKeyRingFrom(signingKeys))
|
||||||
);
|
);
|
||||||
signOut = new ByteArrayOutputStream();
|
signOut = new ByteArrayOutputStream();
|
||||||
StreamUtil.pipeAll(verifier, signOut);
|
Streams.pipeAll(verifier, signOut);
|
||||||
verifier.close();
|
verifier.close();
|
||||||
|
|
||||||
OpenPgpMetadata metadata = verifier.getResult();
|
OpenPgpMetadata metadata = verifier.getResult();
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPLiteralData;
|
import org.bouncycastle.openpgp.PGPLiteralData;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.JUtils;
|
import org.junit.JUtils;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
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.ConsumerOptions;
|
||||||
import org.pgpainless.decryption_verification.DecryptionStream;
|
import org.pgpainless.decryption_verification.DecryptionStream;
|
||||||
import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
import org.pgpainless.decryption_verification.OpenPgpMetadata;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class FileInformationTest {
|
public class FileInformationTest {
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public class FileInformationTest {
|
||||||
.setEncoding(encoding)
|
.setEncoding(encoding)
|
||||||
);
|
);
|
||||||
|
|
||||||
StreamUtil.pipeAll(dataIn, encryptionStream);
|
Streams.pipeAll(dataIn, encryptionStream);
|
||||||
encryptionStream.close();
|
encryptionStream.close();
|
||||||
|
|
||||||
EncryptionResult encResult = encryptionStream.getResult();
|
EncryptionResult encResult = encryptionStream.getResult();
|
||||||
|
@ -87,7 +87,7 @@ public class FileInformationTest {
|
||||||
.onInputStream(cryptIn)
|
.onInputStream(cryptIn)
|
||||||
.withOptions(new ConsumerOptions()
|
.withOptions(new ConsumerOptions()
|
||||||
.addDecryptionKey(secretKey));
|
.addDecryptionKey(secretKey));
|
||||||
StreamUtil.pipeAll(decryptionStream, plainOut);
|
Streams.pipeAll(decryptionStream, plainOut);
|
||||||
|
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ public class FileInformationTest {
|
||||||
.addRecipient(certificate))
|
.addRecipient(certificate))
|
||||||
);
|
);
|
||||||
|
|
||||||
StreamUtil.pipeAll(dataIn, encryptionStream);
|
Streams.pipeAll(dataIn, encryptionStream);
|
||||||
encryptionStream.close();
|
encryptionStream.close();
|
||||||
|
|
||||||
EncryptionResult encResult = encryptionStream.getResult();
|
EncryptionResult encResult = encryptionStream.getResult();
|
||||||
|
@ -126,7 +126,7 @@ public class FileInformationTest {
|
||||||
.onInputStream(cryptIn)
|
.onInputStream(cryptIn)
|
||||||
.withOptions(new ConsumerOptions()
|
.withOptions(new ConsumerOptions()
|
||||||
.addDecryptionKey(secretKey));
|
.addDecryptionKey(secretKey));
|
||||||
StreamUtil.pipeAll(decryptionStream, plainOut);
|
Streams.pipeAll(decryptionStream, plainOut);
|
||||||
|
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ public class FileInformationTest {
|
||||||
.setForYourEyesOnly()
|
.setForYourEyesOnly()
|
||||||
);
|
);
|
||||||
|
|
||||||
StreamUtil.pipeAll(dataIn, encryptionStream);
|
Streams.pipeAll(dataIn, encryptionStream);
|
||||||
encryptionStream.close();
|
encryptionStream.close();
|
||||||
|
|
||||||
EncryptionResult encResult = encryptionStream.getResult();
|
EncryptionResult encResult = encryptionStream.getResult();
|
||||||
|
@ -167,7 +167,7 @@ public class FileInformationTest {
|
||||||
.onInputStream(cryptIn)
|
.onInputStream(cryptIn)
|
||||||
.withOptions(new ConsumerOptions()
|
.withOptions(new ConsumerOptions()
|
||||||
.addDecryptionKey(secretKey));
|
.addDecryptionKey(secretKey));
|
||||||
StreamUtil.pipeAll(decryptionStream, plainOut);
|
Streams.pipeAll(decryptionStream, plainOut);
|
||||||
|
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKey;
|
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
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.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.key.util.KeyRingUtils;
|
import org.pgpainless.key.util.KeyRingUtils;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class SigningTest {
|
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);
|
byte[] messageBytes = "This message is signed and encrypted to Romeo and Juliet.".getBytes(StandardCharsets.UTF_8);
|
||||||
ByteArrayInputStream message = new ByteArrayInputStream(messageBytes);
|
ByteArrayInputStream message = new ByteArrayInputStream(messageBytes);
|
||||||
|
|
||||||
StreamUtil.pipeAll(message, encryptionStream);
|
Streams.pipeAll(message, encryptionStream);
|
||||||
encryptionStream.close();
|
encryptionStream.close();
|
||||||
|
|
||||||
byte[] encrypted = out.toByteArray();
|
byte[] encrypted = out.toByteArray();
|
||||||
|
@ -102,7 +102,7 @@ public class SigningTest {
|
||||||
|
|
||||||
ByteArrayOutputStream plaintextOut = new ByteArrayOutputStream();
|
ByteArrayOutputStream plaintextOut = new ByteArrayOutputStream();
|
||||||
|
|
||||||
StreamUtil.pipeAll(decryptionStream, plaintextOut);
|
Streams.pipeAll(decryptionStream, plaintextOut);
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
|
|
||||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.security.NoSuchAlgorithmException;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.algorithm.DocumentSignatureType;
|
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.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.key.util.KeyRingUtils;
|
import org.pgpainless.key.util.KeyRingUtils;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class Encrypt {
|
public class Encrypt {
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ public class Encrypt {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Pipe data trough and CLOSE the stream (important)
|
// 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();
|
encryptor.close();
|
||||||
String encryptedMessage = ciphertext.toString();
|
String encryptedMessage = ciphertext.toString();
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public class Encrypt {
|
||||||
|
|
||||||
ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
|
ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
|
||||||
|
|
||||||
StreamUtil.pipeAll(decryptor, plaintext);
|
Streams.pipeAll(decryptor, plaintext);
|
||||||
decryptor.close();
|
decryptor.close();
|
||||||
|
|
||||||
// Check the metadata to see how the message was encrypted/signed
|
// Check the metadata to see how the message was encrypted/signed
|
||||||
|
@ -126,7 +126,7 @@ public class Encrypt {
|
||||||
).setAsciiArmor(true)
|
).setAsciiArmor(true)
|
||||||
);
|
);
|
||||||
|
|
||||||
StreamUtil.pipeAll(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)), encryptor);
|
Streams.pipeAll(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)), encryptor);
|
||||||
encryptor.close();
|
encryptor.close();
|
||||||
|
|
||||||
String asciiCiphertext = ciphertext.toString();
|
String asciiCiphertext = ciphertext.toString();
|
||||||
|
@ -137,7 +137,7 @@ public class Encrypt {
|
||||||
.withOptions(new ConsumerOptions().addDecryptionPassphrase(Passphrase.fromPassword("p4ssphr4s3")));
|
.withOptions(new ConsumerOptions().addDecryptionPassphrase(Passphrase.fromPassword("p4ssphr4s3")));
|
||||||
|
|
||||||
ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
|
ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
|
||||||
StreamUtil.pipeAll(decryptor, plaintext);
|
Streams.pipeAll(decryptor, plaintext);
|
||||||
|
|
||||||
decryptor.close();
|
decryptor.close();
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
|
||||||
import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider;
|
import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider;
|
||||||
import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder;
|
import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder;
|
||||||
import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
|
import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.pgpainless.PGPainless;
|
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.PasswordBasedSecretKeyRingProtector;
|
||||||
import org.pgpainless.key.protection.UnlockSecretKey;
|
import org.pgpainless.key.protection.UnlockSecretKey;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class ChangeSecretKeyRingPassphraseTest {
|
public class ChangeSecretKeyRingPassphraseTest {
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ public class ChangeSecretKeyRingPassphraseTest {
|
||||||
.addInlineSignature(PasswordBasedSecretKeyRingProtector.forKey(keyRing, passphrase),
|
.addInlineSignature(PasswordBasedSecretKeyRingProtector.forKey(keyRing, passphrase),
|
||||||
keyRing, DocumentSignatureType.BINARY_DOCUMENT)));
|
keyRing, DocumentSignatureType.BINARY_DOCUMENT)));
|
||||||
|
|
||||||
StreamUtil.pipeAll(new ByteArrayInputStream(dummyMessage.getBytes()), stream);
|
Streams.pipeAll(new ByteArrayInputStream(dummyMessage.getBytes()), stream);
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSignature;
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.decryption_verification.ConsumerOptions;
|
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.decryption_verification.OpenPgpMetadata;
|
||||||
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
import org.pgpainless.key.OpenPgpV4Fingerprint;
|
||||||
import org.pgpainless.key.util.KeyRingUtils;
|
import org.pgpainless.key.util.KeyRingUtils;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if marker packets are being ignored properly.
|
* Test if marker packets are being ignored properly.
|
||||||
|
@ -162,7 +162,7 @@ public class IgnoreMarkerPackets {
|
||||||
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
StreamUtil.pipeAll(decryptionStream, outputStream);
|
Streams.pipeAll(decryptionStream, outputStream);
|
||||||
|
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||||
|
@ -211,7 +211,7 @@ public class IgnoreMarkerPackets {
|
||||||
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
StreamUtil.pipeAll(decryptionStream, outputStream);
|
Streams.pipeAll(decryptionStream, outputStream);
|
||||||
|
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
assertArrayEquals(data.getBytes(StandardCharsets.UTF_8), outputStream.toByteArray());
|
assertArrayEquals(data.getBytes(StandardCharsets.UTF_8), outputStream.toByteArray());
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
|
@ -31,7 +32,6 @@ import org.pgpainless.encryption_signing.EncryptionStream;
|
||||||
import org.pgpainless.encryption_signing.ProducerOptions;
|
import org.pgpainless.encryption_signing.ProducerOptions;
|
||||||
import org.pgpainless.implementation.ImplementationFactory;
|
import org.pgpainless.implementation.ImplementationFactory;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class MultiPassphraseSymmetricEncryptionTest {
|
public class MultiPassphraseSymmetricEncryptionTest {
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class MultiPassphraseSymmetricEncryptionTest {
|
||||||
.addPassphrase(Passphrase.fromPassword("p2"))
|
.addPassphrase(Passphrase.fromPassword("p2"))
|
||||||
).setAsciiArmor(false));
|
).setAsciiArmor(false));
|
||||||
|
|
||||||
StreamUtil.pipeAll(plaintextIn, encryptor);
|
Streams.pipeAll(plaintextIn, encryptor);
|
||||||
encryptor.close();
|
encryptor.close();
|
||||||
|
|
||||||
byte[] ciphertext = ciphertextOut.toByteArray();
|
byte[] ciphertext = ciphertextOut.toByteArray();
|
||||||
|
@ -65,7 +65,7 @@ public class MultiPassphraseSymmetricEncryptionTest {
|
||||||
|
|
||||||
ByteArrayOutputStream plaintextOut = new ByteArrayOutputStream();
|
ByteArrayOutputStream plaintextOut = new ByteArrayOutputStream();
|
||||||
|
|
||||||
StreamUtil.pipeAll(decryptor, plaintextOut);
|
Streams.pipeAll(decryptor, plaintextOut);
|
||||||
|
|
||||||
decryptor.close();
|
decryptor.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Random;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.pgpainless.PGPainless;
|
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.SecretKeyRingProtector;
|
||||||
import org.pgpainless.key.protection.passphrase_provider.SolitaryPassphraseProvider;
|
import org.pgpainless.key.protection.passphrase_provider.SolitaryPassphraseProvider;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test parallel symmetric and public key encryption/decryption.
|
* Test parallel symmetric and public key encryption/decryption.
|
||||||
|
@ -68,7 +68,7 @@ public class SymmetricEncryptionTest {
|
||||||
.addRecipient(encryptionKey)
|
.addRecipient(encryptionKey)
|
||||||
));
|
));
|
||||||
|
|
||||||
StreamUtil.pipeAll(plaintextIn, encryptor);
|
Streams.pipeAll(plaintextIn, encryptor);
|
||||||
encryptor.close();
|
encryptor.close();
|
||||||
|
|
||||||
byte[] ciphertext = ciphertextOut.toByteArray();
|
byte[] ciphertext = ciphertextOut.toByteArray();
|
||||||
|
@ -81,7 +81,7 @@ public class SymmetricEncryptionTest {
|
||||||
|
|
||||||
ByteArrayOutputStream decrypted = new ByteArrayOutputStream();
|
ByteArrayOutputStream decrypted = new ByteArrayOutputStream();
|
||||||
|
|
||||||
StreamUtil.pipeAll(decryptor, decrypted);
|
Streams.pipeAll(decryptor, decrypted);
|
||||||
decryptor.close();
|
decryptor.close();
|
||||||
|
|
||||||
assertArrayEquals(plaintext, decrypted.toByteArray());
|
assertArrayEquals(plaintext, decrypted.toByteArray());
|
||||||
|
@ -98,7 +98,7 @@ public class SymmetricEncryptionTest {
|
||||||
|
|
||||||
decrypted = new ByteArrayOutputStream();
|
decrypted = new ByteArrayOutputStream();
|
||||||
|
|
||||||
StreamUtil.pipeAll(decryptor, decrypted);
|
Streams.pipeAll(decryptor, decrypted);
|
||||||
decryptor.close();
|
decryptor.close();
|
||||||
|
|
||||||
assertArrayEquals(plaintext, decrypted.toByteArray());
|
assertArrayEquals(plaintext, decrypted.toByteArray());
|
||||||
|
@ -118,7 +118,7 @@ public class SymmetricEncryptionTest {
|
||||||
EncryptionOptions.encryptCommunications()
|
EncryptionOptions.encryptCommunications()
|
||||||
.addPassphrase(Passphrase.fromPassword("mellon"))));
|
.addPassphrase(Passphrase.fromPassword("mellon"))));
|
||||||
|
|
||||||
StreamUtil.pipeAll(new ByteArrayInputStream(bytes), encryptor);
|
Streams.pipeAll(new ByteArrayInputStream(bytes), encryptor);
|
||||||
encryptor.close();
|
encryptor.close();
|
||||||
|
|
||||||
assertThrows(MissingDecryptionMethodException.class, () -> PGPainless.decryptAndOrVerify()
|
assertThrows(MissingDecryptionMethodException.class, () -> PGPainless.decryptAndOrVerify()
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.algorithm.EncryptionPurpose;
|
import org.pgpainless.algorithm.EncryptionPurpose;
|
||||||
|
@ -34,7 +35,6 @@ import org.pgpainless.encryption_signing.EncryptionStream;
|
||||||
import org.pgpainless.encryption_signing.ProducerOptions;
|
import org.pgpainless.encryption_signing.ProducerOptions;
|
||||||
import org.pgpainless.key.WeirdKeys;
|
import org.pgpainless.key.WeirdKeys;
|
||||||
import org.pgpainless.key.util.KeyRingUtils;
|
import org.pgpainless.key.util.KeyRingUtils;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
|
|
||||||
public class TestTwoSubkeysEncryption {
|
public class TestTwoSubkeysEncryption {
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ public class TestTwoSubkeysEncryption {
|
||||||
.setAsciiArmor(false)
|
.setAsciiArmor(false)
|
||||||
);
|
);
|
||||||
|
|
||||||
StreamUtil.pipeAll(getPlainIn(), encryptionStream);
|
Streams.pipeAll(getPlainIn(), encryptionStream);
|
||||||
encryptionStream.close();
|
encryptionStream.close();
|
||||||
|
|
||||||
EncryptionResult metadata = encryptionStream.getResult();
|
EncryptionResult metadata = encryptionStream.getResult();
|
||||||
|
|
|
@ -23,8 +23,8 @@ import java.nio.charset.Charset;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.pgpainless.util.ArmoredOutputStreamFactory;
|
import org.pgpainless.util.ArmoredOutputStreamFactory;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
import sop.Ready;
|
import sop.Ready;
|
||||||
import sop.enums.ArmorLabel;
|
import sop.enums.ArmorLabel;
|
||||||
import sop.exception.SOPGPException;
|
import sop.exception.SOPGPException;
|
||||||
|
@ -57,10 +57,10 @@ public class ArmorImpl implements Armor {
|
||||||
int read = pbIn.read(buffer);
|
int read = pbIn.read(buffer);
|
||||||
pbIn.unread(buffer, 0, read);
|
pbIn.unread(buffer, 0, read);
|
||||||
if (!allowNested && Arrays.equals(ARMOR_START, buffer)) {
|
if (!allowNested && Arrays.equals(ARMOR_START, buffer)) {
|
||||||
StreamUtil.pipeAll(pbIn, System.out);
|
Streams.pipeAll(pbIn, System.out);
|
||||||
} else {
|
} else {
|
||||||
ArmoredOutputStream armor = ArmoredOutputStreamFactory.get(System.out);
|
ArmoredOutputStream armor = ArmoredOutputStreamFactory.get(System.out);
|
||||||
StreamUtil.pipeAll(pbIn, armor);
|
Streams.pipeAll(pbIn, armor);
|
||||||
armor.close();
|
armor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.bouncycastle.openpgp.PGPUtil;
|
import org.bouncycastle.openpgp.PGPUtil;
|
||||||
import org.pgpainless.util.StreamUtil;
|
import org.bouncycastle.util.io.Streams;
|
||||||
import sop.Ready;
|
import sop.Ready;
|
||||||
import sop.operation.Dearmor;
|
import sop.operation.Dearmor;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public class DearmorImpl implements Dearmor {
|
||||||
return new Ready() {
|
return new Ready() {
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(OutputStream outputStream) throws IOException {
|
public void writeTo(OutputStream outputStream) throws IOException {
|
||||||
StreamUtil.pipeAll(decoder, outputStream);
|
Streams.pipeAll(decoder, outputStream);
|
||||||
decoder.close();
|
decoder.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||||
import org.bouncycastle.openpgp.PGPSignature;
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.decryption_verification.ConsumerOptions;
|
import org.pgpainless.decryption_verification.ConsumerOptions;
|
||||||
import org.pgpainless.decryption_verification.DecryptionStream;
|
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.info.KeyRingInfo;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
import sop.DecryptionResult;
|
import sop.DecryptionResult;
|
||||||
import sop.ReadyWithResult;
|
import sop.ReadyWithResult;
|
||||||
import sop.SessionKey;
|
import sop.SessionKey;
|
||||||
|
@ -151,7 +151,7 @@ public class DecryptImpl implements Decrypt {
|
||||||
return new ReadyWithResult<DecryptionResult>() {
|
return new ReadyWithResult<DecryptionResult>() {
|
||||||
@Override
|
@Override
|
||||||
public DecryptionResult writeTo(OutputStream outputStream) throws IOException, SOPGPException.NoSignature {
|
public DecryptionResult writeTo(OutputStream outputStream) throws IOException, SOPGPException.NoSignature {
|
||||||
StreamUtil.pipeAll(decryptionStream, outputStream);
|
Streams.pipeAll(decryptionStream, outputStream);
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.io.OutputStream;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.algorithm.DocumentSignatureType;
|
import org.pgpainless.algorithm.DocumentSignatureType;
|
||||||
import org.pgpainless.algorithm.StreamEncoding;
|
import org.pgpainless.algorithm.StreamEncoding;
|
||||||
|
@ -32,12 +33,11 @@ import org.pgpainless.encryption_signing.SigningOptions;
|
||||||
import org.pgpainless.exception.WrongPassphraseException;
|
import org.pgpainless.exception.WrongPassphraseException;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
import org.pgpainless.util.StreamUtil;
|
import sop.util.ProxyOutputStream;
|
||||||
import sop.Ready;
|
import sop.Ready;
|
||||||
import sop.enums.EncryptAs;
|
import sop.enums.EncryptAs;
|
||||||
import sop.exception.SOPGPException;
|
import sop.exception.SOPGPException;
|
||||||
import sop.operation.Encrypt;
|
import sop.operation.Encrypt;
|
||||||
import sop.util.ProxyOutputStream;
|
|
||||||
|
|
||||||
public class EncryptImpl implements Encrypt {
|
public class EncryptImpl implements Encrypt {
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ public class EncryptImpl implements Encrypt {
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(OutputStream outputStream) throws IOException {
|
public void writeTo(OutputStream outputStream) throws IOException {
|
||||||
proxy.replaceOutputStream(outputStream);
|
proxy.replaceOutputStream(outputStream);
|
||||||
StreamUtil.pipeAll(plaintext, encryptionStream);
|
Streams.pipeAll(plaintext, encryptionStream);
|
||||||
encryptionStream.close();
|
encryptionStream.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
||||||
import org.bouncycastle.openpgp.PGPException;
|
import org.bouncycastle.openpgp.PGPException;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSignature;
|
import org.bouncycastle.openpgp.PGPSignature;
|
||||||
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.algorithm.DocumentSignatureType;
|
import org.pgpainless.algorithm.DocumentSignatureType;
|
||||||
import org.pgpainless.encryption_signing.EncryptionResult;
|
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.info.KeyRingInfo;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.util.ArmoredOutputStreamFactory;
|
import org.pgpainless.util.ArmoredOutputStreamFactory;
|
||||||
import org.pgpainless.util.StreamUtil;
|
|
||||||
import sop.Ready;
|
import sop.Ready;
|
||||||
import sop.enums.SignAs;
|
import sop.enums.SignAs;
|
||||||
import sop.exception.SOPGPException;
|
import sop.exception.SOPGPException;
|
||||||
|
@ -92,7 +92,7 @@ public class SignImpl implements Sign {
|
||||||
throw new IllegalStateException("EncryptionStream is already closed.");
|
throw new IllegalStateException("EncryptionStream is already closed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamUtil.pipeAll(data, signingStream);
|
Streams.pipeAll(data, signingStream);
|
||||||
signingStream.close();
|
signingStream.close();
|
||||||
EncryptionResult encryptionResult = signingStream.getResult();
|
EncryptionResult encryptionResult = signingStream.getResult();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue