Пример #1
0
        protected void WriteHeader(StreamWriter writer, SshPublicKeyHeader header)
        {
            using (var headerStream = new MemoryStream())
            {
                // Write header tag.
                var tagData = Encoding.ASCII.GetBytes(header.Tag + ": ");
                headerStream.Write(tagData, 0, tagData.Length);

                // Write header value.
                var valueData = Encoding.UTF8.GetBytes(header.Value);
                headerStream.Write(valueData, 0, valueData.Length);

                // Write header text to output stream.
                var headerText     = writer.Encoding.GetString(headerStream.ToArray());
                int bytesRemaining = 0;

                for (int i = 0; i < headerText.Length; i += _lineMaxByteLength - 1)
                {
                    bytesRemaining = headerText.Length - i;

                    // Check if this is last line to write.
                    if (bytesRemaining <= _lineMaxByteLength)
                    {
                        // Write all remaining bytes.
                        writer.WriteLine(headerText.Substring(i, bytesRemaining));
                    }
                    else
                    {
                        // Write current line.
                        writer.WriteLine(headerText.Substring(i, _lineMaxByteLength - 1) + "\\");
                    }
                }
            }
        }
Пример #2
0
        protected void WriteHeader(StreamWriter writer, SshPublicKeyHeader header)
        {
            using (var headerStream = new MemoryStream())
            {
                // Write header tag.
                var tagData = Encoding.ASCII.GetBytes(header.Tag + ": ");
                headerStream.Write(tagData, 0, tagData.Length);

                // Write header value.
                var valueData = Encoding.UTF8.GetBytes(header.Value);
                headerStream.Write(valueData, 0, valueData.Length);

                // Write header text to output stream.
                var headerText = writer.Encoding.GetString(headerStream.ToArray());
                int bytesRemaining = 0;

                for (int i = 0; i < headerText.Length; i += _lineMaxByteLength - 1)
                {
                    bytesRemaining = headerText.Length - i;

                    // Check if this is last line to write.
                    if (bytesRemaining <= _lineMaxByteLength)
                    {
                        // Write all remaining bytes.
                        writer.WriteLine(headerText.Substring(i, bytesRemaining));
                    }
                    else
                    {
                        // Write current line.
                        writer.WriteLine(headerText.Substring(i, _lineMaxByteLength - 1) + "\\");
                    }
                }
            }
        }