From dd419227622288468173d9435d645e7c70b03d06 Mon Sep 17 00:00:00 2001
From: Paul Schaub <vanitasvitae@fsfe.org>
Date: Mon, 24 Feb 2025 11:26:21 +0100
Subject: [PATCH] WIP: Tinkering with CRLF encoding

---
 .../OpenPgpMessageInputStream.kt              |  2 ++
 .../CRLFInputStreamTest.kt                    | 29 +++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 pgpainless-core/src/test/kotlin/org/pgpainless/decryption_verification/CRLFInputStreamTest.kt

diff --git a/pgpainless-core/src/main/kotlin/org/pgpainless/decryption_verification/OpenPgpMessageInputStream.kt b/pgpainless-core/src/main/kotlin/org/pgpainless/decryption_verification/OpenPgpMessageInputStream.kt
index bd24b245..dd77207c 100644
--- a/pgpainless-core/src/main/kotlin/org/pgpainless/decryption_verification/OpenPgpMessageInputStream.kt
+++ b/pgpainless-core/src/main/kotlin/org/pgpainless/decryption_verification/OpenPgpMessageInputStream.kt
@@ -5,6 +5,7 @@
 package org.pgpainless.decryption_verification
 
 import java.io.EOFException
+import java.io.FilterInputStream
 import java.io.IOException
 import java.io.InputStream
 import java.io.OutputStream
@@ -18,6 +19,7 @@ import org.bouncycastle.openpgp.PGPCompressedData
 import org.bouncycastle.openpgp.PGPEncryptedData
 import org.bouncycastle.openpgp.PGPEncryptedDataList
 import org.bouncycastle.openpgp.PGPException
+import org.bouncycastle.openpgp.PGPLiteralData
 import org.bouncycastle.openpgp.PGPOnePassSignature
 import org.bouncycastle.openpgp.PGPPBEEncryptedData
 import org.bouncycastle.openpgp.PGPPrivateKey
diff --git a/pgpainless-core/src/test/kotlin/org/pgpainless/decryption_verification/CRLFInputStreamTest.kt b/pgpainless-core/src/test/kotlin/org/pgpainless/decryption_verification/CRLFInputStreamTest.kt
new file mode 100644
index 00000000..f078bb2c
--- /dev/null
+++ b/pgpainless-core/src/test/kotlin/org/pgpainless/decryption_verification/CRLFInputStreamTest.kt
@@ -0,0 +1,29 @@
+package org.pgpainless.decryption_verification
+
+import org.bouncycastle.util.io.Streams
+import org.junit.jupiter.api.Assertions.assertArrayEquals
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Test
+
+class CRLFInputStreamTest {
+
+    @Test
+    fun readRNOneByOne() {
+        val bIn = "a\r\nb".byteInputStream()
+        val crlfIn = OpenPgpMessageInputStream.CRLFInputStream(bIn)
+
+        assertEquals('a'.code, crlfIn.read())
+        assertEquals('\n'.code, crlfIn.read())
+        assertEquals('b'.code, crlfIn.read())
+        assertEquals(-1, crlfIn.read())
+    }
+
+    @Test
+    fun readRNAtOnce() {
+        val bIn = "a\r\nb".byteInputStream()
+        val crlfIn = OpenPgpMessageInputStream.CRLFInputStream(bIn)
+
+        val bytes = Streams.readAll(crlfIn)
+        assertArrayEquals("a\nb".toByteArray(), bytes)
+    }
+}