Org.BouncyCastle.OpenSsl.PemReader.ReadBytesAndFields C# (CSharp) Method

ReadBytesAndFields() private method

private ReadBytesAndFields ( string endMarker, IDictionary fields ) : byte[]
endMarker string
fields IDictionary
return byte[]
		private byte[] ReadBytesAndFields(
			string		endMarker,
			IDictionary	fields)
		{
			StringBuilder buf = new StringBuilder();

			string line;
			while ((line = reader.ReadLine()) != null
				&& line.IndexOf(endMarker) == -1)
			{
				int colonPos = line.IndexOf(':');

				if (colonPos == -1)
				{
					buf.Append(line.Trim());
				}
				else if (fields != null)
				{
					// Process field
					string fieldName = line.Substring(0, colonPos).Trim();

					if (fieldName.StartsWith("X-"))
						fieldName = fieldName.Substring(2);

					string fieldValue = line.Substring(colonPos + 1).Trim();

					// TODO Complain if field already specified?
					fields[fieldName] = fieldValue;
				}
			}

			if (line == null)
			{
				throw new IOException(endMarker + " not found");
			}

			if (buf.Length % 4 != 0)
			{
				throw new IOException("base64 data appears to be truncated");
			}

			return Base64.Decode(buf.ToString());
		}