mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 02:09:38 +02:00
commit
d5845d94a0
2 changed files with 18 additions and 6 deletions
|
@ -37,7 +37,7 @@ class CRLFGeneratorStream(private val crlfOut: OutputStream, encoding: StreamEnc
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
if (!isBinary && lastB == 'r'.code) {
|
if (!isBinary && lastB == '\r'.code) {
|
||||||
crlfOut.write('\n'.code)
|
crlfOut.write('\n'.code)
|
||||||
}
|
}
|
||||||
crlfOut.close()
|
crlfOut.close()
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||||
import org.bouncycastle.bcpg.CompressionAlgorithmTags;
|
import org.bouncycastle.bcpg.CompressionAlgorithmTags;
|
||||||
|
@ -30,6 +31,9 @@ import org.bouncycastle.openpgp.operator.bc.BcPGPContentSignerBuilder;
|
||||||
import org.bouncycastle.util.io.Streams;
|
import org.bouncycastle.util.io.Streams;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.algorithm.DocumentSignatureType;
|
import org.pgpainless.algorithm.DocumentSignatureType;
|
||||||
import org.pgpainless.algorithm.HashAlgorithm;
|
import org.pgpainless.algorithm.HashAlgorithm;
|
||||||
|
@ -288,11 +292,9 @@ public class CanonicalizedDataEncryptionTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void resultOfDecryptionIsCRLFEncoded() throws PGPException, IOException {
|
@MethodSource("resultOfDecryptionIsCRLFEncodedArguments")
|
||||||
String before = "Foo\nBar!\n";
|
public void resultOfDecryptionIsCRLFEncoded(String before, String after) throws PGPException, IOException {
|
||||||
String after = "Foo\r\nBar!\r\n";
|
|
||||||
|
|
||||||
String encrypted = encryptAndSign(before, DocumentSignatureType.BINARY_DOCUMENT, StreamEncoding.TEXT, true);
|
String encrypted = encryptAndSign(before, DocumentSignatureType.BINARY_DOCUMENT, StreamEncoding.TEXT, true);
|
||||||
|
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(encrypted.getBytes(StandardCharsets.UTF_8));
|
ByteArrayInputStream in = new ByteArrayInputStream(encrypted.getBytes(StandardCharsets.UTF_8));
|
||||||
|
@ -309,6 +311,16 @@ public class CanonicalizedDataEncryptionTest {
|
||||||
assertArrayEquals(after.getBytes(StandardCharsets.UTF_8), decrypted.toByteArray());
|
assertArrayEquals(after.getBytes(StandardCharsets.UTF_8), decrypted.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Stream<Arguments> resultOfDecryptionIsCRLFEncodedArguments() {
|
||||||
|
return Stream.of(
|
||||||
|
Arguments.of("foo", "foo"),
|
||||||
|
Arguments.of("rrr", "rrr"),
|
||||||
|
Arguments.of("Foo\nBar!\n", "Foo\r\nBar!\r\n"),
|
||||||
|
Arguments.of("Foo\rBar!\r", "Foo\r\nBar!\r\n"),
|
||||||
|
Arguments.of("Foo\r\nBar!\r\n", "Foo\r\nBar!\r\n")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resultOfDecryptionIsNotCRLFEncoded() throws PGPException, IOException {
|
public void resultOfDecryptionIsNotCRLFEncoded() throws PGPException, IOException {
|
||||||
String beforeAndAfter = "Foo\nBar!\n";
|
String beforeAndAfter = "Foo\nBar!\n";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue