using System; namespace S22.Sasl.Mechanisms.Srp { /// /// Represents an "octet-sequence" as is described in the SRP specification /// (3.3 Octet sequences, p.6). /// internal class OctetSequence { /// /// The underlying byte array forming this instance of the OctetSequence /// class. /// public byte[] Value { get; set; } /// /// Creates a new instance of the OctetSequence class using the specified /// byte array. /// /// The sequence of bytes to initialize this instance /// of the OctetSequence class with. public OctetSequence(byte[] sequence) { Value = sequence; } /// /// Serializes this instance of the OctetSequence class into a sequence of /// bytes according to the requirements of the SRP specification. /// /// A sequence of bytes representing this instance of the /// OctetSequence class. /// Thrown if the length of the byte /// sequence exceeds the maximum number of bytes allowed as per SRP /// specification. /// SRP specification imposes a limit of 255 bytes on the /// length of the underlying byte array. public byte[] Serialize() { byte length = Convert.ToByte(Value.Length); return new ByteBuilder() .Append(length) .Append(Value) .ToArray(); } } }