using System;
namespace S22.Sasl.Mechanisms.Ntlm {
///
/// Represents an NTLM security buffer, which is a structure used to point
/// to a buffer of binary data within an NTLM message.
///
internal class SecurityBuffer {
///
/// The length of the buffer content in bytes (may be zero).
///
public short Length {
get;
private set;
}
///
/// The allocated space for the buffer in bytes (typically the same as
/// the length).
///
public short AllocatedSpace {
get {
return Length;
}
}
///
/// The offset from the beginning of the NTLM message to the start of
/// the buffer, in bytes.
///
public int Offset {
get;
private set;
}
///
/// Creates a new instance of the SecurityBuffer class using the specified
/// values.
///
/// The length of the buffer described by this instance
/// of the SecurityBuffer class.
/// The offset at which the buffer starts, in bytes.
/// Thrown if the length value exceeds
/// the maximum value allowed. The security buffer structure stores the
/// length value as a 2-byte short value.
public SecurityBuffer(int length, int offset) {
Length = Convert.ToInt16(length);
Offset = offset;
}
///
/// Creates a new instance of the SecurityBuffer class using the specified
/// values.
///
/// The data of the buffer described by this instance
/// of the SecurityBuffer class.
/// The offset at which the buffer starts, in bytes.
/// Thrown if the length of the data
/// buffer exceeds the maximum value allowed. The security buffer structure
/// stores the buffer length value as a 2-byte short value.
public SecurityBuffer(byte[] data, int offset)
: this(data.Length, offset) {
}
///
/// Serializes this instance of the SecurityBuffer into an array of bytes.
///
/// A byte array representing this instance of the SecurityBuffer
/// class.
public byte[] Serialize() {
return new ByteBuilder()
.Append(Length)
.Append(AllocatedSpace)
.Append(Offset)
.ToArray();
}
}
}