public ConstructHeader ( int length ) : byte[] | ||
length | int | The length of the packet to make a header for. |
return | byte[] |
public byte[] ConstructHeader(int length)
{
if (length < 2)
{
throw new ArgumentOutOfRangeException("length", length, CommonStrings.PacketLengthMustBeMoreThan2Bytes);
}
int encodedVersion = ((this.iv[2] << 8) | this.iv[3]) ^ this.versionMask;
int encodedLength = encodedVersion ^ (((length & 0xFF) << 8) | (length >> 8));
var header = new byte[4];
unchecked
{
header[0] = (byte)(encodedVersion >> 8);
header[1] = (byte)encodedVersion;
header[2] = (byte)(encodedLength >> 8);
header[3] = (byte)encodedLength;
}
return header;
}
/// <summary> /// Constructs a packet header and encodes the given length in it. /// </summary> /// <remarks> /// When overriding this method in a derived class, /// do not call the base implementation. /// </remarks> /// <param name="length">The length of the packet.</param> /// <returns>a 4-element byte array which should be prepended to the packet data.</returns> private byte[] ConstructHeader(int length) { return(_encryptor.ConstructHeader(length)); }