summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-06-07 02:54:10 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-06-07 02:54:10 +0700
commitef229edc7a3c0ae8967d0ae038f8b8b5d15d1557 (patch)
tree8199ae4bcef18a2596b031c1c72c49ae704c249e
parentUpdate TLS test data from bc-java (diff)
downloadBouncyCastle.NET-ed25519-ef229edc7a3c0ae8967d0ae038f8b8b5d15d1557.tar.xz
Update from bc-java
-rw-r--r--crypto/src/util/io/pem/PemReader.cs55
1 files changed, 23 insertions, 32 deletions
diff --git a/crypto/src/util/io/pem/PemReader.cs b/crypto/src/util/io/pem/PemReader.cs
index 61e132fa7..b806c7f63 100644
--- a/crypto/src/util/io/pem/PemReader.cs
+++ b/crypto/src/util/io/pem/PemReader.cs
@@ -33,12 +33,17 @@ namespace Org.BouncyCastle.Utilities.IO.Pem
 		/// <exception cref="IOException"></exception>
 		public PemObject ReadPemObject()
 		{
-			string line = reader.ReadLine();
+            string line = reader.ReadLine();
 
-            if (line != null && Platform.StartsWith(line, BeginString))
-			{
-				line = line.Substring(BeginString.Length);
-				int index = line.IndexOf('-');
+            while (line != null && !Platform.StartsWith(line, BeginString)) 
+            {
+                line = reader.ReadLine();
+            }
+
+            if (line != null)
+            {
+                line = line.Substring(BeginString.Length);
+                int index = line.IndexOf('-');
 
                 if (index > 0 && Platform.EndsWith(line, "-----") && (line.Length - index) == 5)
                 {
@@ -48,7 +53,7 @@ namespace Org.BouncyCastle.Utilities.IO.Pem
                 }
             }
 
-			return null;
+            return null;
 		}
 
 		private PemObject LoadObject(string type)
@@ -58,40 +63,26 @@ namespace Org.BouncyCastle.Utilities.IO.Pem
 			StringBuilder buf = new StringBuilder();
 
 			string line;
-			while ((line = reader.ReadLine()) != null
-                && Platform.IndexOf(line, endMarker) == -1)
+			while ((line = reader.ReadLine()) != null)
 			{
 				int colonPos = line.IndexOf(':');
-
-				if (colonPos == -1)
-				{
-					buf.Append(line.Trim());
-				}
-				else
+				if (colonPos >= 0)
 				{
-					// Process field
-					string fieldName = line.Substring(0, colonPos).Trim();
+                    string hdr = line.Substring(0, colonPos).Trim();
+                    string val = line.Substring(colonPos + 1).Trim();
 
-                    if (Platform.StartsWith(fieldName, "X-"))
-                    {
-                        fieldName = fieldName.Substring(2);
-                    }
+                    headers.Add(new PemHeader(hdr, val));
+                    continue;
+				}
 
-					string fieldValue = line.Substring(colonPos + 1).Trim();
+                if (Platform.IndexOf(line, endMarker) >= 0)
+                    break;
 
-					headers.Add(new PemHeader(fieldName, fieldValue));
-				}
-			}
+                buf.Append(line.Trim());
+            }
 
-			if (line == null)
-			{
+            if (line == null)
 				throw new IOException(endMarker + " not found");
-			}
-
-			if (buf.Length % 4 != 0)
-			{
-				throw new IOException("base64 data appears to be truncated");
-			}
 
 			return new PemObject(type, headers, Base64.Decode(buf.ToString()));
 		}