mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
Remove Tuple class
This commit is contained in:
parent
57b6795513
commit
312a00e5d4
2 changed files with 54 additions and 77 deletions
|
@ -49,7 +49,6 @@ import org.pgpainless.exception.MalformedOpenPgpMessageException;
|
|||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.util.ArmoredInputStreamFactory;
|
||||
import org.pgpainless.util.Passphrase;
|
||||
import org.pgpainless.util.Tuple;
|
||||
|
||||
public class OpenPgpMessageInputStreamTest {
|
||||
|
||||
|
@ -313,7 +312,17 @@ public class OpenPgpMessageInputStreamTest {
|
|||
}
|
||||
|
||||
interface Processor {
|
||||
Tuple<String, MessageMetadata> process(String armoredMessage, ConsumerOptions options) throws PGPException, IOException;
|
||||
Result process(String armoredMessage, ConsumerOptions options) throws PGPException, IOException;
|
||||
}
|
||||
|
||||
static class Result {
|
||||
private final String plaintext;
|
||||
private final MessageMetadata metadata;
|
||||
|
||||
Result(String plaintext, MessageMetadata metadata) {
|
||||
this.plaintext = plaintext;
|
||||
this.metadata = metadata;
|
||||
}
|
||||
}
|
||||
|
||||
private static Stream<Arguments> provideMessageProcessors() {
|
||||
|
@ -325,12 +334,12 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
@ParameterizedTest(name = "Process LIT using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessLIT(Processor processor) throws IOException, PGPException {
|
||||
Tuple<String, MessageMetadata> result = processor.process(LIT, ConsumerOptions.get());
|
||||
String plain = result.getA();
|
||||
void testProcessLIT(Processor processor) throws IOException, PGPException {
|
||||
Result result = processor.process(LIT, ConsumerOptions.get());
|
||||
String plain = result.plaintext;
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
|
||||
MessageMetadata metadata = result.getB();
|
||||
MessageMetadata metadata = result.metadata;
|
||||
assertNull(metadata.getCompressionAlgorithm());
|
||||
assertNull(metadata.getEncryptionAlgorithm());
|
||||
assertEquals("", metadata.getFilename());
|
||||
|
@ -342,19 +351,19 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
@ParameterizedTest(name = "Process LIT LIT using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessLIT_LIT_fails(Processor processor) {
|
||||
void testProcessLIT_LIT_fails(Processor processor) {
|
||||
assertThrows(MalformedOpenPgpMessageException.class,
|
||||
() -> processor.process(LIT_LIT, ConsumerOptions.get()));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "Process COMP(LIT) using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessCOMP_LIT(Processor processor)
|
||||
void testProcessCOMP_LIT(Processor processor)
|
||||
throws PGPException, IOException {
|
||||
Tuple<String, MessageMetadata> result = processor.process(COMP_LIT, ConsumerOptions.get());
|
||||
String plain = result.getA();
|
||||
Result result = processor.process(COMP_LIT, ConsumerOptions.get());
|
||||
String plain = result.plaintext;
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
MessageMetadata metadata = result.getB();
|
||||
MessageMetadata metadata = result.metadata;
|
||||
assertEquals(CompressionAlgorithm.ZIP, metadata.getCompressionAlgorithm());
|
||||
assertTrue(metadata.getVerifiedInlineSignatures().isEmpty());
|
||||
assertTrue(metadata.getRejectedInlineSignatures().isEmpty());
|
||||
|
@ -362,19 +371,19 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
@ParameterizedTest(name = "Process COMP using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessCOMP_fails(Processor processor) {
|
||||
void testProcessCOMP_fails(Processor processor) {
|
||||
assertThrows(MalformedOpenPgpMessageException.class,
|
||||
() -> processor.process(COMP, ConsumerOptions.get()));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "Process COMP(COMP(LIT)) using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessCOMP_COMP_LIT(Processor processor)
|
||||
void testProcessCOMP_COMP_LIT(Processor processor)
|
||||
throws PGPException, IOException {
|
||||
Tuple<String, MessageMetadata> result = processor.process(COMP_COMP_LIT, ConsumerOptions.get());
|
||||
String plain = result.getA();
|
||||
Result result = processor.process(COMP_COMP_LIT, ConsumerOptions.get());
|
||||
String plain = result.plaintext;
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
MessageMetadata metadata = result.getB();
|
||||
MessageMetadata metadata = result.metadata;
|
||||
assertEquals(CompressionAlgorithm.ZIP, metadata.getCompressionAlgorithm());
|
||||
Iterator<CompressionAlgorithm> compressionAlgorithms = metadata.getCompressionAlgorithms();
|
||||
assertEquals(CompressionAlgorithm.ZIP, compressionAlgorithms.next());
|
||||
|
@ -387,16 +396,16 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
@ParameterizedTest(name = "Process SIG COMP(LIT) using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessSIG_COMP_LIT(Processor processor)
|
||||
void testProcessSIG_COMP_LIT(Processor processor)
|
||||
throws PGPException, IOException {
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(
|
||||
PGPainless.readKeyRing().secretKeyRing(KEY));
|
||||
|
||||
Tuple<String, MessageMetadata> result = processor.process(SIG_COMP_LIT, ConsumerOptions.get()
|
||||
Result result = processor.process(SIG_COMP_LIT, ConsumerOptions.get()
|
||||
.addVerificationCert(cert));
|
||||
String plain = result.getA();
|
||||
String plain = result.plaintext;
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
MessageMetadata metadata = result.getB();
|
||||
MessageMetadata metadata = result.metadata;
|
||||
assertEquals(CompressionAlgorithm.ZIP, metadata.getCompressionAlgorithm());
|
||||
assertNull(metadata.getEncryptionAlgorithm());
|
||||
assertFalse(metadata.getVerifiedInlineSignatures().isEmpty());
|
||||
|
@ -405,13 +414,13 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
@ParameterizedTest(name = "Process SENC(LIT) using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessSENC_LIT(Processor processor)
|
||||
void testProcessSENC_LIT(Processor processor)
|
||||
throws PGPException, IOException {
|
||||
Tuple<String, MessageMetadata> result = processor.process(SENC_LIT, ConsumerOptions.get()
|
||||
Result result = processor.process(SENC_LIT, ConsumerOptions.get()
|
||||
.addMessagePassphrase(Passphrase.fromPassword(PASSPHRASE)));
|
||||
String plain = result.getA();
|
||||
String plain = result.plaintext;
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
MessageMetadata metadata = result.getB();
|
||||
MessageMetadata metadata = result.metadata;
|
||||
assertNull(metadata.getCompressionAlgorithm());
|
||||
assertEquals(SymmetricKeyAlgorithm.AES_256, metadata.getEncryptionAlgorithm());
|
||||
assertTrue(metadata.getVerifiedInlineSignatures().isEmpty());
|
||||
|
@ -420,14 +429,14 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
@ParameterizedTest(name = "Process PENC(COMP(LIT)) using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessPENC_COMP_LIT(Processor processor)
|
||||
void testProcessPENC_COMP_LIT(Processor processor)
|
||||
throws IOException, PGPException {
|
||||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
|
||||
Tuple<String, MessageMetadata> result = processor.process(PENC_COMP_LIT, ConsumerOptions.get()
|
||||
Result result = processor.process(PENC_COMP_LIT, ConsumerOptions.get()
|
||||
.addDecryptionKey(secretKeys));
|
||||
String plain = result.getA();
|
||||
String plain = result.plaintext;
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
MessageMetadata metadata = result.getB();
|
||||
MessageMetadata metadata = result.metadata;
|
||||
assertEquals(CompressionAlgorithm.ZLIB, metadata.getCompressionAlgorithm());
|
||||
assertEquals(SymmetricKeyAlgorithm.AES_256, metadata.getEncryptionAlgorithm());
|
||||
assertTrue(metadata.getVerifiedInlineSignatures().isEmpty());
|
||||
|
@ -436,14 +445,14 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
@ParameterizedTest(name = "Process OPS LIT SIG using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessOPS_LIT_SIG(Processor processor)
|
||||
void testProcessOPS_LIT_SIG(Processor processor)
|
||||
throws IOException, PGPException {
|
||||
PGPPublicKeyRing cert = PGPainless.extractCertificate(PGPainless.readKeyRing().secretKeyRing(KEY));
|
||||
Tuple<String, MessageMetadata> result = processor.process(OPS_LIT_SIG, ConsumerOptions.get()
|
||||
Result result = processor.process(OPS_LIT_SIG, ConsumerOptions.get()
|
||||
.addVerificationCert(cert));
|
||||
String plain = result.getA();
|
||||
String plain = result.plaintext;
|
||||
assertEquals(PLAINTEXT, plain);
|
||||
MessageMetadata metadata = result.getB();
|
||||
MessageMetadata metadata = result.metadata;
|
||||
assertNull(metadata.getEncryptionAlgorithm());
|
||||
assertNull(metadata.getCompressionAlgorithm());
|
||||
assertFalse(metadata.getVerifiedInlineSignatures().isEmpty());
|
||||
|
@ -535,7 +544,7 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
@ParameterizedTest(name = "Process PENC(OPS OPS LIT SIG SIG) using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessPENC_OPS_OPS_LIT_SIG_SIG(Processor processor) throws IOException, PGPException {
|
||||
void testProcessPENC_OPS_OPS_LIT_SIG_SIG(Processor processor) throws IOException, PGPException {
|
||||
String MSG = "-----BEGIN PGP MESSAGE-----\n" +
|
||||
"\n" +
|
||||
"wcDMA3wvqk35PDeyAQv/RhY9sgxMXj1UxumNMOeN+1+c5bB5e3jSrvA93L8yLFqB\n" +
|
||||
|
@ -575,12 +584,12 @@ public class OpenPgpMessageInputStreamTest {
|
|||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(BOB_KEY);
|
||||
PGPPublicKeyRing certificate = PGPainless.extractCertificate(secretKeys);
|
||||
|
||||
Tuple<String, MessageMetadata> result = processor.process(MSG, ConsumerOptions.get()
|
||||
Result result = processor.process(MSG, ConsumerOptions.get()
|
||||
.addVerificationCert(certificate)
|
||||
.addDecryptionKey(secretKeys));
|
||||
String plain = result.getA();
|
||||
String plain = result.plaintext;
|
||||
assertEquals("encrypt ∘ sign ∘ sign", plain);
|
||||
MessageMetadata metadata = result.getB();
|
||||
MessageMetadata metadata = result.metadata;
|
||||
assertEquals(SymmetricKeyAlgorithm.AES_256, metadata.getEncryptionAlgorithm());
|
||||
assertNull(metadata.getCompressionAlgorithm());
|
||||
assertFalse(metadata.getVerifiedInlineSignatures().isEmpty());
|
||||
|
@ -589,7 +598,7 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
@ParameterizedTest(name = "Process PENC(OPS OPS OPS LIT SIG SIG SIG) using {0}")
|
||||
@MethodSource("provideMessageProcessors")
|
||||
public void testProcessOPS_OPS_OPS_LIT_SIG_SIG_SIG(Processor processor) throws IOException, PGPException {
|
||||
void testProcessOPS_OPS_OPS_LIT_SIG_SIG_SIG(Processor processor) throws IOException, PGPException {
|
||||
String MSG = "-----BEGIN PGP MESSAGE-----\n" +
|
||||
"\n" +
|
||||
"wcDMA3wvqk35PDeyAQwA0yaEgydkAMEfl7rDTYVGanLKiFiWIs34mkF+LB8qR5eY\n" +
|
||||
|
@ -640,12 +649,12 @@ public class OpenPgpMessageInputStreamTest {
|
|||
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(BOB_KEY);
|
||||
PGPPublicKeyRing certificate = PGPainless.extractCertificate(secretKeys);
|
||||
|
||||
Tuple<String, MessageMetadata> result = processor.process(MSG, ConsumerOptions.get()
|
||||
Result result = processor.process(MSG, ConsumerOptions.get()
|
||||
.addVerificationCert(certificate)
|
||||
.addDecryptionKey(secretKeys));
|
||||
String plain = result.getA();
|
||||
String plain = result.plaintext;
|
||||
assertEquals("encrypt ∘ sign ∘ sign ∘ sign", plain);
|
||||
MessageMetadata metadata = result.getB();
|
||||
MessageMetadata metadata = result.metadata;
|
||||
assertEquals(SymmetricKeyAlgorithm.AES_256, metadata.getEncryptionAlgorithm());
|
||||
assertNull(metadata.getCompressionAlgorithm());
|
||||
assertFalse(metadata.getVerifiedInlineSignatures().isEmpty());
|
||||
|
@ -653,7 +662,7 @@ public class OpenPgpMessageInputStreamTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void readAfterCloseTest() throws IOException {
|
||||
void readAfterCloseTest() throws IOException {
|
||||
OpenPgpMessageInputStream pgpIn = get(SENC_LIT, ConsumerOptions.get()
|
||||
.addMessagePassphrase(Passphrase.fromPassword(PASSPHRASE)));
|
||||
Streams.drain(pgpIn); // read all
|
||||
|
@ -668,17 +677,17 @@ public class OpenPgpMessageInputStreamTest {
|
|||
pgpIn.getMetadata();
|
||||
}
|
||||
|
||||
private static Tuple<String, MessageMetadata> processReadBuffered(String armoredMessage, ConsumerOptions options)
|
||||
private static Result processReadBuffered(String armoredMessage, ConsumerOptions options)
|
||||
throws IOException {
|
||||
OpenPgpMessageInputStream in = get(armoredMessage, options);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
Streams.pipeAll(in, out);
|
||||
in.close();
|
||||
MessageMetadata metadata = in.getMetadata();
|
||||
return new Tuple<>(out.toString(), metadata);
|
||||
return new Result(out.toString(), metadata);
|
||||
}
|
||||
|
||||
private static Tuple<String, MessageMetadata> processReadSequential(String armoredMessage, ConsumerOptions options)
|
||||
private static Result processReadSequential(String armoredMessage, ConsumerOptions options)
|
||||
throws IOException {
|
||||
OpenPgpMessageInputStream in = get(armoredMessage, options);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
@ -690,7 +699,7 @@ public class OpenPgpMessageInputStreamTest {
|
|||
|
||||
in.close();
|
||||
MessageMetadata metadata = in.getMetadata();
|
||||
return new Tuple<>(out.toString(), metadata);
|
||||
return new Result(out.toString(), metadata);
|
||||
}
|
||||
|
||||
private static OpenPgpMessageInputStream get(String armored, ConsumerOptions options)
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.util;
|
||||
|
||||
/**
|
||||
* Helper class pairing together two values.
|
||||
* @param <A> type of the first value
|
||||
* @param <B> type of the second value
|
||||
* @deprecated Scheduled for removal.
|
||||
* TODO: Remove
|
||||
*/
|
||||
@Deprecated
|
||||
public class Tuple<A, B> {
|
||||
|
||||
private final A a;
|
||||
private final B b;
|
||||
|
||||
public Tuple(A a, B b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public A getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public B getB() {
|
||||
return b;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue