Ignore missing CRC checksums by default, but allow modification of this behavior
*/
private static final byte[] decodingTable;
+ /*
+ * Ignore missing CRC checksums.
+ * https://tests.sequoia-pgp.org/#ASCII_Armor suggests that missing CRC sums do not invalidate the message.
+ */
+ private boolean ignoreMissingCRCSum = true;
+
static
{
decodingTable = new byte[128];
@@ -433,10 +439,13 @@ else if (newLineFound && c == '-')
return read();
}
else
+ {
+ if (!ignoreMissingCRCSum)
{
throw new IOException("no crc found in armored message.");
}
}
+ }
else if (c == '-') // end of record reached
{
while ((c = in.read()) >= 0)
@@ -447,7 +456,7 @@ else if (c == '-') // end of record reached
}
}
- if (!crcFound)
+ if (!crcFound && !ignoreMissingCRCSum)
{
throw new IOException("crc check not found.");
}
@@ -550,4 +559,17 @@ public void close()
{
in.close();
}
+
+ /**
+ * Change how the stream should react if it encounters missing CRC checksum.
+ * The default value is true (ignore missing CRC checksums).
+ *
+ * If the behavior is set to false, an {@link IOException} will
+ * be thrown if a missing CRC checksum is encountered.
+ *
+ * @param ignoreMissing ignore missing CRC sums
+ */
+ public void setIgnoreMissingCRCSum(boolean ignoreMissing) {
+ this.ignoreMissingCRCSum = ignoreMissing;
+ }
}
