mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
Fix tests
This commit is contained in:
parent
e86062c427
commit
d81c0d4400
4 changed files with 98 additions and 10 deletions
|
@ -2,8 +2,10 @@ package org.pgpainless.decryption_verification;
|
|||
|
||||
import org.bouncycastle.bcpg.ArmoredInputStream;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.PGPainless;
|
||||
import org.pgpainless.exception.MalformedOpenPgpMessageException;
|
||||
import org.pgpainless.util.ArmoredInputStreamFactory;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
|
@ -18,9 +20,11 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||
import static org.pgpainless.decryption_verification.PGPDecryptionStreamTest.COMP;
|
||||
import static org.pgpainless.decryption_verification.PGPDecryptionStreamTest.COMP_COMP_LIT;
|
||||
import static org.pgpainless.decryption_verification.PGPDecryptionStreamTest.COMP_LIT;
|
||||
import static org.pgpainless.decryption_verification.PGPDecryptionStreamTest.KEY;
|
||||
import static org.pgpainless.decryption_verification.PGPDecryptionStreamTest.LIT;
|
||||
import static org.pgpainless.decryption_verification.PGPDecryptionStreamTest.LIT_LIT;
|
||||
import static org.pgpainless.decryption_verification.PGPDecryptionStreamTest.PASSPHRASE;
|
||||
import static org.pgpainless.decryption_verification.PGPDecryptionStreamTest.PENC_COMP_LIT;
|
||||
import static org.pgpainless.decryption_verification.PGPDecryptionStreamTest.PLAINTEXT;
|
||||
import static org.pgpainless.decryption_verification.PGPDecryptionStreamTest.SENC_LIT;
|
||||
import static org.pgpainless.decryption_verification.PGPDecryptionStreamTest.SIG_LIT;
|
||||
|
@ -69,6 +73,14 @@ public class OpenPgpMessageInputStreamTest {
|
|||
assertEquals(PLAINTEXT, plain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessPENC_COMP_LIT() throws IOException, PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
|
||||
String plain = process(PENC_COMP_LIT, ConsumerOptions.get()
|
||||
.addDecryptionKey(secretKeys));
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
}
|
||||
|
||||
private String process(String armoredMessage, ConsumerOptions options) throws PGPException, IOException {
|
||||
OpenPgpMessageInputStream in = get(armoredMessage, options);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.bouncycastle.openpgp.PGPCompressedDataGenerator;
|
|||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPLiteralData;
|
||||
import org.bouncycastle.openpgp.PGPLiteralDataGenerator;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.util.io.Streams;
|
||||
|
@ -124,6 +125,17 @@ public class PGPDecryptionStreamTest {
|
|||
"=i4Y0\n" +
|
||||
"-----END PGP MESSAGE-----";
|
||||
|
||||
public static final String PENC_COMP_LIT = "" +
|
||||
"-----BEGIN PGP MESSAGE-----\n" +
|
||||
"Version: PGPainless\n" +
|
||||
"\n" +
|
||||
"hF4Dyqa/GWUy6WsSAQdAQ62BwmUt8Iby0+jvrLhMgST79KR/as+dyl0nf1uki2sw\n" +
|
||||
"Thg1Ojtf0hOyJgcpQ4nP2Q0wYFR0F1sCydaIlTGreYZHlGtybP7/Ml6KNZILTRWP\n" +
|
||||
"0kYBkGBgK7oQWRIVyoF2POvEP6EX1X8nvQk7O3NysVdRVbnia7gE3AzRYuha4kxs\n" +
|
||||
"pI6xJkntLMS3K6him1Y9FHINIASFSB+C\n" +
|
||||
"=5p00\n" +
|
||||
"-----END PGP MESSAGE-----";
|
||||
|
||||
@Test
|
||||
public void genLIT() throws IOException {
|
||||
ArmoredOutputStream armorOut = new ArmoredOutputStream(System.out);
|
||||
|
@ -328,4 +340,22 @@ public class PGPDecryptionStreamTest {
|
|||
|
||||
System.out.println(out);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void genPENC_COMP_LIT() throws IOException, PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(secretKeys);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
EncryptionStream enc = PGPainless.encryptAndOrSign()
|
||||
.onOutputStream(out)
|
||||
.withOptions(ProducerOptions.encrypt(EncryptionOptions.get()
|
||||
.addRecipient(cert))
|
||||
.overrideCompressionAlgorithm(CompressionAlgorithm.ZLIB));
|
||||
|
||||
Streams.pipeAll(new ByteArrayInputStream(PLAINTEXT.getBytes(StandardCharsets.UTF_8)), enc);
|
||||
enc.close();
|
||||
|
||||
System.out.println(out);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue