Add test for comment round-tripping
package org.bouncycastle.openpgp.test;
+import org.bouncycastle.bcpg.ArmoredInputStream;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.util.test.SimpleTest;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.Charset;
@@ -32,6 +34,10 @@ public void performTest() throws Exception {
armorOut.close();
String armoredOutput = out.toString();
+ ByteArrayInputStream bytesIn = new ByteArrayInputStream(armoredOutput.getBytes(utf8));
+ ArmoredInputStream armorIn = new ArmoredInputStream(bytesIn);
+ String[] header = armorIn.getArmorHeaders();
+
String[] lines = armoredOutput.split("\n");
String comment = null;
for (String line : lines) {
@@ -43,5 +49,8 @@ public void performTest() throws Exception {
isTrue("We did not find the comment line. This MUST never happen.", comment != null);
isEquals("Comment was not properly encoded. Expected: " +utf8WithUmlauts + ", Actual: " + comment, comment, utf8WithUmlauts);
+
+ // round-tripped comment from ascii armor input stream
+ isEquals(header[1].substring("Comment: ".length()), utf8WithUmlauts);
}
}
