1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-04-22 06:24:47 +02:00

Merge pull request from bjansen/bugfix/gh-469

Fix for 
This commit is contained in:
Paul Schaub 2025-03-11 19:51:08 +01:00 committed by GitHub
commit d5845d94a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 6 deletions
pgpainless-core/src
main/kotlin/org/pgpainless/encryption_signing
test/java/org/pgpainless/decryption_verification

View file

@ -37,7 +37,7 @@ class CRLFGeneratorStream(private val crlfOut: OutputStream, encoding: StreamEnc
}
override fun close() {
if (!isBinary && lastB == 'r'.code) {
if (!isBinary && lastB == '\r'.code) {
crlfOut.write('\n'.code)
}
crlfOut.close()

View file

@ -13,6 +13,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.stream.Stream;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.bcpg.CompressionAlgorithmTags;
@ -30,6 +31,9 @@ import org.bouncycastle.openpgp.operator.bc.BcPGPContentSignerBuilder;
import org.bouncycastle.util.io.Streams;
import org.junit.jupiter.api.BeforeAll;
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.algorithm.DocumentSignatureType;
import org.pgpainless.algorithm.HashAlgorithm;
@ -288,11 +292,9 @@ public class CanonicalizedDataEncryptionTest {
}
}
@Test
public void resultOfDecryptionIsCRLFEncoded() throws PGPException, IOException {
String before = "Foo\nBar!\n";
String after = "Foo\r\nBar!\r\n";
@ParameterizedTest
@MethodSource("resultOfDecryptionIsCRLFEncodedArguments")
public void resultOfDecryptionIsCRLFEncoded(String before, String after) throws PGPException, IOException {
String encrypted = encryptAndSign(before, DocumentSignatureType.BINARY_DOCUMENT, StreamEncoding.TEXT, true);
ByteArrayInputStream in = new ByteArrayInputStream(encrypted.getBytes(StandardCharsets.UTF_8));
@ -309,6 +311,16 @@ public class CanonicalizedDataEncryptionTest {
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
public void resultOfDecryptionIsNotCRLFEncoded() throws PGPException, IOException {
String beforeAndAfter = "Foo\nBar!\n";