mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-22 20:32:05 +01:00
Workaround for #159: Avoid to prevent swallowing IOExceptions
This commit is contained in:
parent
10bb033e40
commit
fc311fe781
25 changed files with 216 additions and 72 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
|
||||||
);
|
);
|
||||||
|
|
||||||
Streams.pipeAll(plaintextInputStream, encryptionStream);
|
StreamUtil.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)
|
||||||
);
|
);
|
||||||
|
|
||||||
Streams.pipeAll(decryptionStream, outputStream);
|
StreamUtil.pipeAll(decryptionStream, outputStream);
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
|
|
||||||
// Result contains information like signature status etc.
|
// Result contains information like signature status etc.
|
||||||
|
|
|
@ -36,7 +36,6 @@ 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;
|
||||||
|
@ -46,6 +45,7 @@ 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);
|
||||||
Streams.pipeAll(new ByteArrayInputStream(aliceKeys.getEncoded()), aliceKeyOut);
|
StreamUtil.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);
|
||||||
Streams.pipeAll(new ByteArrayInputStream(alicePub.getEncoded()), aliceCertOut);
|
StreamUtil.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);
|
||||||
Streams.pipeAll(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)), dataOut);
|
StreamUtil.pipeAll(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)), dataOut);
|
||||||
dataOut.close();
|
dataOut.close();
|
||||||
|
|
||||||
// Sign test data
|
// Sign test data
|
||||||
|
|
|
@ -32,7 +32,6 @@ 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;
|
||||||
|
|
||||||
|
@ -143,7 +142,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);
|
||||||
Streams.pipeAll(inputStream, armor);
|
StreamUtil.pipeAll(inputStream, armor);
|
||||||
armor.close();
|
armor.close();
|
||||||
|
|
||||||
return out.toString();
|
return out.toString();
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
* 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.bouncycastle;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import org.bouncycastle.bcpg.ArmoredInputStream;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.pgpainless.util.StreamUtil;
|
||||||
|
|
||||||
|
public class WrongArmorChecksumTest {
|
||||||
|
|
||||||
|
// According to https://github.com/FlowCrypt/flowcrypt-android/issues/1347
|
||||||
|
// this message contains a wrong CRC checksum in the ascii armor
|
||||||
|
public static final String MESSAGE_WITH_WRONG_ARMOR_CHECKSUM = "" +
|
||||||
|
"-----BEGIN PGP MESSAGE-----\n" +
|
||||||
|
"Version: FlowCrypt 5.0.4 Gmail Encryption flowcrypt.com\n" +
|
||||||
|
"Comment: Seamlessly send, receive and search encrypted email\n" +
|
||||||
|
"\n" +
|
||||||
|
"wcFMA+ADv/5v4RgKAQ/+K2rrAqhjMe9FLCfklI9Y30Woktg0Q/xe71EVw6WO\n" +
|
||||||
|
"tVD/VK+xv4CHzi+HojtE0U2F+vqoPSO0q5TN9giKPMTiK25PnCzfd7Q+zXiF\n" +
|
||||||
|
"j+5RSHTVJxC62qLHhtKsAQtC4asub8cQIFXbZz3Ns4+7jKtSWPcRqhKTurWv\n" +
|
||||||
|
"XVH0YAFJDsFYo26r2V9c+Ie0uoQPx8graEGpKO9GtoQjXMKK32oApuBSSlmS\n" +
|
||||||
|
"Q+nxyxMx1V+gxP4qgGBCxqkBFRYB/Ve6ygNHL1KxxCVTEw9pgnxJscn89Iio\n" +
|
||||||
|
"dO6qZ9EgIV0PVQN0Yw033MTgAhCHunlE/qXvDxib4tdihoNsLN0q5kdOeiMW\n" +
|
||||||
|
"+ntm3kphjMpQ6TMCUGtdS7UmvnadZ+dh5s785M8S9oY64mQd6QuYA2iy1IQv\n" +
|
||||||
|
"q3zpW4/ba2gqL36qCCw/OaruXpQ4NeBr3hMaJQjWgeSuMsQnNGYUn5Nn1+9X\n" +
|
||||||
|
"wtlithO8eLi3M1dg19dpDky8CacWfGgHD7SNsZ2zqFqyd1qtdFcit5ynQUHS\n" +
|
||||||
|
"IiJKeUknGv1dQAnPPJ1FdXyyqC/VDBZG6CNdnxjonmQDRh1YlqNwSnmrR/Sy\n" +
|
||||||
|
"X7n+nGra+/0EHJW6ohaSdep2jAwJDelq/DI1lqiN16ZXJ2/WH6pItA9tmkLU\n" +
|
||||||
|
"61QUz6qwPAnd0t6iy/YkOi2/s1+dwC0DwOcZoUPF8bTBwUwDS1ov/OYtlQEB\n" +
|
||||||
|
"D/46rCPRZrX34ipseTkZxtw3YPhbNkNHo95Mzh9lpeaaZIqtUg2yiFUnhwLi\n" +
|
||||||
|
"tYwyBCkXCb92l1GXXxGSmvSLDSKfQfIpZ0rV5j50MYKIpjSeJZyH/3qP+JXv\n" +
|
||||||
|
"Z47GsTp0z5/oNau5XQwuhLhUtRoZd1WS9ahSJ1akiKeYJroLbTg10fjL25yp\n" +
|
||||||
|
"iaoV16SqKA1H/JOuj6lT5z1nuez35JjeSpUc7ksdot60ZovMfWC+OGRnkYKb\n" +
|
||||||
|
"7KxFd7uaxL6uOBOFyvRxYeohKd73aVkiKpcWd4orI18FhlftFNAwIdsmfzNc\n" +
|
||||||
|
"mzTHZaUl89iYxEKR6ae6AKws1wzLq0noarsf2eKBVbTSfmK3S3xFqduKINnc\n" +
|
||||||
|
"e5Yb3F5adSj1dUjm1BZ4aqzsgKyBb+J8keG9ESsnFOyxOIUXDM1nIo1IOgzC\n" +
|
||||||
|
"M928Jb9GVa+uhdXRrb5cLjTihTusJN0I8oJrwKkwIpCJVgPMdDLkeubrMBQ4\n" +
|
||||||
|
"fbpl4V76sOU2Nx+6nG2FnFBFBFohOL+0nTK5/6Ns9ateN7K9VP++QcoeqfPk\n" +
|
||||||
|
"IUO3+lCZW+trTSvvFId3ziUVsPTeuAS+7nxSMfWZ/K9Ci6QV/Xnx3F/qSmuS\n" +
|
||||||
|
"AUm4zPQ1EjZf1N/5K+vhcCTN4MMx406VlqtedkXL2KPwZ6jDS/ww8RfcmPnD\n" +
|
||||||
|
"s94ct0WCZZtNlnQq+5h0ybwTJNLC2QFyrhhPqztVY95n9La2Mw5WITCWzg/d\n" +
|
||||||
|
"IBUceW/OwHYtePyaSQkCnegDw/2mN2/GC8d0OlwULcTYG6uVenGv2UOUbCr3\n" +
|
||||||
|
"Pfy/Eb/VqUEZK00PdvVQV7FWYAshuTFPTqidph04CgQvBpi3SDEEo8SkEIFS\n" +
|
||||||
|
"/iEeRQaWjFEXKUI3FwKXPJQWvFpbrXBOAjnxXXbAFYOLxdydmq1GVl9Mm3GU\n" +
|
||||||
|
"Clc9g6t9vaYDBPx2gN562/CM/nT8Vq45VHe79XkrrcHDwLn7yeHJScNFsib+\n" +
|
||||||
|
"VvwTPoUftlhC/ai21D403TsJpm7ZmPcDjagoIcXrS/lN03z79RBmSKFtYiXW\n" +
|
||||||
|
"4obkKSGow61vMBh2/XLVYKJKpYKm/GnVlJxA0zQVl558x8I/nAMaxSzwx+ZY\n" +
|
||||||
|
"waVU/s5PLZ7Ghg3MOguiRTlflKUQyL0A7NR46OjFgUnHAZRxr4KO3GoxVPy4\n" +
|
||||||
|
"XLeS4+Wl68s7QlV6WF1IKCHWEUMEeRRea2/OvvlS/oLs2MNNWDemlJ4SiXHf\n" +
|
||||||
|
"xINU38Txo84A00NALbKppsSyy9Gwj//rO/FcerupkfeuOm9nHFwIQeeC5bWD\n" +
|
||||||
|
"mmRlC90r2jY8gM/v3Jjy9h8PbXWxh9MUpc7/kAcTwdGlMxiVjE29p065qTRr\n" +
|
||||||
|
"Oi6sJ7pWuYTfWldZqTVmaBjlv0zuXQ8Eo8o/USvoTs+oihYIMcqReqdeqr/N\n" +
|
||||||
|
"e+sDtYKRg/LKp/JJ5nAQzVMP67DxkgwLNxx0ijBLysaQmvRlsiYWayxZB1Xd\n" +
|
||||||
|
"BxA2bjZRvsmww+hgSKNlcsiubJGBqfqvgmlebZuJHHSC1L6mdMYgcihKmYAj\n" +
|
||||||
|
"p+HFLyqgyeRVMdjRHcrEdxNPG4fJmlk1bYiVQQ4XAd72w+AHS/seZ5HzbAK0\n" +
|
||||||
|
"omuHYUD5PTEqZ1K9JObSsh3XMUkJK+z3BnrOxnTOOyG2r+4FxizH6rfz/Pgg\n" +
|
||||||
|
"sPxqxE9ELUlgQe8plcPFge6aN9tUoSe+vMtDaEAqKw9JwofBF7jlxTqMMvQC\n" +
|
||||||
|
"gWbn9x3W5o4VrnpjYGtPl8sh1QREu0A+0PUJAKL4A3GSMYRouGewLSMNJlOg\n" +
|
||||||
|
"/0pPF6qB+Fi4GJ7ju5C07tfr9z9UqRj09kDXJuoJd95NdSiCz6ndugn6gs8B\n" +
|
||||||
|
"Qf/XPxZVefeMLiB6p8pG0iZ/jcJjyYJLtTg6kA+1/ffmJPfH/76ZA9dgEJLj\n" +
|
||||||
|
"/W2u0Lp4NY8cwqcXuGKgl72TVJ34Iawl35Y0yr47k/7Y1vEQ5Q3bT7HP5A==\n" +
|
||||||
|
"=FdCC\n" +
|
||||||
|
"-----END PGP MESSAGE-----";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertReadingFaultyArmorMessageFails() throws IOException {
|
||||||
|
ByteArrayInputStream bytes = new ByteArrayInputStream(MESSAGE_WITH_WRONG_ARMOR_CHECKSUM.getBytes(StandardCharsets.UTF_8));
|
||||||
|
ArmoredInputStream armorIn = new ArmoredInputStream(bytes);
|
||||||
|
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
assertThrows(IOException.class, () -> {
|
||||||
|
StreamUtil.pipeAll(armorIn, out);
|
||||||
|
armorIn.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();
|
||||||
Streams.pipeAll(fileIn, bytes);
|
StreamUtil.pipeAll(fileIn, bytes);
|
||||||
fileIn.close();
|
fileIn.close();
|
||||||
assertArrayEquals(message.getBytes(StandardCharsets.UTF_8), bytes.toByteArray());
|
assertArrayEquals(message.getBytes(StandardCharsets.UTF_8), bytes.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ 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;
|
||||||
|
@ -37,6 +36,7 @@ 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();
|
||||||
Streams.pipeAll(decryptor, toPlain);
|
StreamUtil.pipeAll(decryptor, toPlain);
|
||||||
decryptor.close();
|
decryptor.close();
|
||||||
toPlain.close();
|
toPlain.close();
|
||||||
OpenPgpMetadata metadata = decryptor.getResult();
|
OpenPgpMetadata metadata = decryptor.getResult();
|
||||||
|
|
|
@ -26,7 +26,6 @@ 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;
|
||||||
|
@ -34,6 +33,7 @@ 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();
|
||||||
Streams.pipeAll(decryptionStream, out);
|
StreamUtil.pipeAll(decryptionStream, out);
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
|
|
||||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||||
|
|
|
@ -28,7 +28,6 @@ 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;
|
||||||
|
@ -38,6 +37,7 @@ 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, () -> {
|
||||||
Streams.pipeAll(decryptionStream, outputStream);
|
StreamUtil.pipeAll(decryptionStream, outputStream);
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ public class ModificationDetectionTests {
|
||||||
);
|
);
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Streams.pipeAll(decryptionStream, out);
|
StreamUtil.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();
|
||||||
Streams.pipeAll(decryptionStream, out);
|
StreamUtil.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();
|
||||||
Streams.pipeAll(decryptionStream, outputStream);
|
StreamUtil.pipeAll(decryptionStream, outputStream);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ 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;
|
||||||
|
@ -43,6 +42,7 @@ 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
|
||||||
)));
|
)));
|
||||||
Streams.pipeAll(new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8)), signingStream);
|
StreamUtil.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();
|
||||||
Streams.pipeAll(verificationStream, plainOut);
|
StreamUtil.pipeAll(verificationStream, plainOut);
|
||||||
verificationStream.close();
|
verificationStream.close();
|
||||||
|
|
||||||
assertArrayEquals(msg.getBytes(StandardCharsets.UTF_8), plainOut.toByteArray());
|
assertArrayEquals(msg.getBytes(StandardCharsets.UTF_8), plainOut.toByteArray());
|
||||||
|
|
|
@ -34,7 +34,6 @@ 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;
|
||||||
|
@ -59,6 +58,7 @@ 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)
|
||||||
));
|
));
|
||||||
|
|
||||||
Streams.pipeAll(new ByteArrayInputStream(secretMessage), encryptor);
|
StreamUtil.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();
|
||||||
|
|
||||||
Streams.pipeAll(decryptor, decryptedSecretMessage);
|
StreamUtil.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)
|
||||||
));
|
));
|
||||||
Streams.pipeAll(inputStream, signer);
|
StreamUtil.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();
|
||||||
Streams.pipeAll(verifier, dummyOut);
|
StreamUtil.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));
|
||||||
Streams.pipeAll(inputStream, signer);
|
StreamUtil.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();
|
||||||
Streams.pipeAll(verifier, signOut);
|
StreamUtil.pipeAll(verifier, signOut);
|
||||||
verifier.close();
|
verifier.close();
|
||||||
|
|
||||||
OpenPgpMetadata metadata = verifier.getResult();
|
OpenPgpMetadata metadata = verifier.getResult();
|
||||||
|
|
|
@ -31,7 +31,6 @@ 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;
|
||||||
|
@ -40,6 +39,7 @@ 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)
|
||||||
);
|
);
|
||||||
|
|
||||||
Streams.pipeAll(dataIn, encryptionStream);
|
StreamUtil.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));
|
||||||
Streams.pipeAll(decryptionStream, plainOut);
|
StreamUtil.pipeAll(decryptionStream, plainOut);
|
||||||
|
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ public class FileInformationTest {
|
||||||
.addRecipient(certificate))
|
.addRecipient(certificate))
|
||||||
);
|
);
|
||||||
|
|
||||||
Streams.pipeAll(dataIn, encryptionStream);
|
StreamUtil.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));
|
||||||
Streams.pipeAll(decryptionStream, plainOut);
|
StreamUtil.pipeAll(decryptionStream, plainOut);
|
||||||
|
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ public class FileInformationTest {
|
||||||
.setForYourEyesOnly()
|
.setForYourEyesOnly()
|
||||||
);
|
);
|
||||||
|
|
||||||
Streams.pipeAll(dataIn, encryptionStream);
|
StreamUtil.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));
|
||||||
Streams.pipeAll(decryptionStream, plainOut);
|
StreamUtil.pipeAll(decryptionStream, plainOut);
|
||||||
|
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ 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;
|
||||||
|
@ -49,6 +48,7 @@ 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);
|
||||||
|
|
||||||
Streams.pipeAll(message, encryptionStream);
|
StreamUtil.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();
|
||||||
|
|
||||||
Streams.pipeAll(decryptionStream, plaintextOut);
|
StreamUtil.pipeAll(decryptionStream, plaintextOut);
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
|
|
||||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||||
|
|
|
@ -28,7 +28,6 @@ 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;
|
||||||
|
@ -42,6 +41,7 @@ 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)
|
||||||
Streams.pipeAll(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)), encryptor);
|
StreamUtil.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();
|
||||||
|
|
||||||
Streams.pipeAll(decryptor, plaintext);
|
StreamUtil.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)
|
||||||
);
|
);
|
||||||
|
|
||||||
Streams.pipeAll(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)), encryptor);
|
StreamUtil.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();
|
||||||
Streams.pipeAll(decryptor, plaintext);
|
StreamUtil.pipeAll(decryptor, plaintext);
|
||||||
|
|
||||||
decryptor.close();
|
decryptor.close();
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ 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;
|
||||||
|
@ -47,6 +46,7 @@ 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)));
|
||||||
|
|
||||||
Streams.pipeAll(new ByteArrayInputStream(dummyMessage.getBytes()), stream);
|
StreamUtil.pipeAll(new ByteArrayInputStream(dummyMessage.getBytes()), stream);
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ 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;
|
||||||
|
@ -38,6 +37,7 @@ 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();
|
||||||
|
|
||||||
Streams.pipeAll(decryptionStream, outputStream);
|
StreamUtil.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();
|
||||||
|
|
||||||
Streams.pipeAll(decryptionStream, outputStream);
|
StreamUtil.pipeAll(decryptionStream, outputStream);
|
||||||
|
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
assertArrayEquals(data.getBytes(StandardCharsets.UTF_8), outputStream.toByteArray());
|
assertArrayEquals(data.getBytes(StandardCharsets.UTF_8), outputStream.toByteArray());
|
||||||
|
|
|
@ -21,7 +21,6 @@ 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;
|
||||||
|
@ -32,6 +31,7 @@ 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));
|
||||||
|
|
||||||
Streams.pipeAll(plaintextIn, encryptor);
|
StreamUtil.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();
|
||||||
|
|
||||||
Streams.pipeAll(decryptor, plaintextOut);
|
StreamUtil.pipeAll(decryptor, plaintextOut);
|
||||||
|
|
||||||
decryptor.close();
|
decryptor.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ 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;
|
||||||
|
@ -44,6 +43,7 @@ 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)
|
||||||
));
|
));
|
||||||
|
|
||||||
Streams.pipeAll(plaintextIn, encryptor);
|
StreamUtil.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();
|
||||||
|
|
||||||
Streams.pipeAll(decryptor, decrypted);
|
StreamUtil.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();
|
||||||
|
|
||||||
Streams.pipeAll(decryptor, decrypted);
|
StreamUtil.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"))));
|
||||||
|
|
||||||
Streams.pipeAll(new ByteArrayInputStream(bytes), encryptor);
|
StreamUtil.pipeAll(new ByteArrayInputStream(bytes), encryptor);
|
||||||
encryptor.close();
|
encryptor.close();
|
||||||
|
|
||||||
assertThrows(MissingDecryptionMethodException.class, () -> PGPainless.decryptAndOrVerify()
|
assertThrows(MissingDecryptionMethodException.class, () -> PGPainless.decryptAndOrVerify()
|
||||||
|
|
|
@ -25,7 +25,6 @@ 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;
|
||||||
|
@ -35,6 +34,7 @@ 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)
|
||||||
);
|
);
|
||||||
|
|
||||||
Streams.pipeAll(getPlainIn(), encryptionStream);
|
StreamUtil.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)) {
|
||||||
Streams.pipeAll(pbIn, System.out);
|
StreamUtil.pipeAll(pbIn, System.out);
|
||||||
} else {
|
} else {
|
||||||
ArmoredOutputStream armor = ArmoredOutputStreamFactory.get(System.out);
|
ArmoredOutputStream armor = ArmoredOutputStreamFactory.get(System.out);
|
||||||
Streams.pipeAll(pbIn, armor);
|
StreamUtil.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.bouncycastle.util.io.Streams;
|
import org.pgpainless.util.StreamUtil;
|
||||||
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 {
|
||||||
Streams.pipeAll(decoder, outputStream);
|
StreamUtil.pipeAll(decoder, outputStream);
|
||||||
decoder.close();
|
decoder.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,7 +27,6 @@ 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;
|
||||||
|
@ -37,6 +36,7 @@ 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 {
|
||||||
Streams.pipeAll(decryptionStream, outputStream);
|
StreamUtil.pipeAll(decryptionStream, outputStream);
|
||||||
decryptionStream.close();
|
decryptionStream.close();
|
||||||
OpenPgpMetadata metadata = decryptionStream.getResult();
|
OpenPgpMetadata metadata = decryptionStream.getResult();
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ 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;
|
||||||
|
@ -33,11 +32,12 @@ 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 sop.util.ProxyOutputStream;
|
import org.pgpainless.util.StreamUtil;
|
||||||
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);
|
||||||
Streams.pipeAll(plaintext, encryptionStream);
|
StreamUtil.pipeAll(plaintext, encryptionStream);
|
||||||
encryptionStream.close();
|
encryptionStream.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,7 +25,6 @@ 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;
|
||||||
|
@ -36,6 +35,7 @@ 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.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Streams.pipeAll(data, signingStream);
|
StreamUtil.pipeAll(data, signingStream);
|
||||||
signingStream.close();
|
signingStream.close();
|
||||||
EncryptionResult encryptionResult = signingStream.getResult();
|
EncryptionResult encryptionResult = signingStream.getResult();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue