using System; using System.IO; using System.Text; namespace S22.Sasl.Mechanisms.Ntlm { /// /// Adds extension methods to the BinaryReader class to simplify the /// deserialization of NTLM messages. /// internal static class BinaryReaderExtensions { /// /// Reads an ASCII-string of the specified length from this instance. /// /// Extension method for the BinaryReader class. /// The number of bytes to read from the underlying /// stream. /// A string decoded from the bytes read from the underlying /// stream using the ASCII character set. public static string ReadASCIIString(this BinaryReader reader, int count) { ByteBuilder builder = new ByteBuilder(); int read = 0; while (true) { if (read++ >= count) break; byte b = reader.ReadByte(); builder.Append(b); } return Encoding.ASCII.GetString(builder.ToArray()).TrimEnd('\0'); } } }