1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-10 14:21:09 +01:00

ArmoredInputStreams: Properly catch ignorable IOExceptions caused by missing CRC sums

This commit is contained in:
Paul Schaub 2021-08-08 15:35:05 +02:00
parent 089b81b070
commit 1983cfb4ac
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 143 additions and 1 deletions

View file

@ -20,6 +20,13 @@ import java.io.InputStream;
import org.bouncycastle.bcpg.ArmoredInputStream;
/**
* Utility class that causes read(bytes, offset, length) to properly throw exceptions
* caused by faulty CRC checksums.
*
* Furthermore, this class swallows exceptions from BC's ArmoredInputStream that are caused
* by missing CRC checksums.
*/
public class CRCingArmoredInputStreamWrapper extends ArmoredInputStream {
private final ArmoredInputStream inputStream;
@ -63,7 +70,16 @@ public class CRCingArmoredInputStreamWrapper extends ArmoredInputStream {
@Override
public int read() throws IOException {
return inputStream.read();
try {
return inputStream.read();
} catch (IOException e) {
if (e.getMessage().equals("no crc found in armored message.") || e.getMessage().equals("crc check not found.")) {
// swallow exception
return -1;
} else {
throw e;
}
}
}
@Override