summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-02-28 11:50:13 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-02-28 11:50:13 +0700
commitfa41ccff1fb9050108798161769d45f1e385a870 (patch)
tree516eb141d7100c4c80de73f28c0aebc232161f48
parentFIx TODOs in Asn1InputStream (diff)
downloadBouncyCastle.NET-ed25519-fa41ccff1fb9050108798161769d45f1e385a870.tar.xz
Exception on malformed checksum
-rw-r--r--crypto/src/bcpg/ArmoredInputStream.cs29
1 files changed, 10 insertions, 19 deletions
diff --git a/crypto/src/bcpg/ArmoredInputStream.cs b/crypto/src/bcpg/ArmoredInputStream.cs
index 348f0bc32..739d78083 100644
--- a/crypto/src/bcpg/ArmoredInputStream.cs
+++ b/crypto/src/bcpg/ArmoredInputStream.cs
@@ -429,27 +429,18 @@ namespace Org.BouncyCastle.Bcpg
                     if (c == '=')            // crc reached
                     {
                         bufPtr = Decode(ReadIgnoreSpace(), ReadIgnoreSpace(), ReadIgnoreSpace(), ReadIgnoreSpace(), outBuf);
-                        if (bufPtr == 0)
-                        {
-                            int i = ((outBuf[0] & 0xff) << 16)
-                                    | ((outBuf[1] & 0xff) << 8)
-                                    | (outBuf[2] & 0xff);
+                        if (bufPtr != 0)
+                            throw new IOException("malformed crc in armored message.");
 
-                            crcFound = true;
+                        crcFound = true;
 
-                            if (i != crc.Value)
-                            {
-                                throw new IOException("crc check failed in armored message.");
-                            }
-                            return ReadByte();
-                        }
-                        else
-                        {
-                            if (detectMissingChecksum)
-                            {
-                                throw new IOException("no crc found in armored message");
-                            }
-                        }
+                        int i = ((outBuf[0] & 0xff) << 16)
+                              | ((outBuf[1] & 0xff) << 8)
+                              | (outBuf[2] & 0xff);
+                        if (i != crc.Value)
+                            throw new IOException("crc check failed in armored message.");
+
+                        return ReadByte();
                     }
                     else if (c == '-')        // end of record reached
                     {