private byte[] EncodeFpHeaderData(int dataLength)
{
List<byte> fpHeaderData = new List<byte>();
RdpbcgrEncoder.EncodeStructure(fpHeaderData, fpInputHeader);
int totalLength = Marshal.SizeOf(fpInputHeader) + Marshal.SizeOf(length1) + dataLength;
if (context.RdpEncryptionLevel == EncryptionLevel.ENCRYPTION_LEVEL_FIPS)
{
totalLength += Marshal.SizeOf(fipsInformation);
}
if (context.RdpEncryptionLevel != EncryptionLevel.ENCRYPTION_LEVEL_NONE)
{
totalLength += dataSignature.Length;
}
// if the most significant bit of the length1 field is set
if (totalLength > 0x7F)
{
++totalLength;
// The overall PDU length is given by the low 7 bits of the length1 field
// concatenated with the 8 bits of the length2 field, in big-endian order
// (the length2 field contains the low-order bits).
length1 = (byte)((totalLength >> 8) | 0x80);
length2 = (byte)(totalLength & 0xFF);
RdpbcgrEncoder.EncodeStructure(fpHeaderData, length1);
RdpbcgrEncoder.EncodeStructure(fpHeaderData, length2);
}
else
{
// If the most significant bit of the length1 field is not set, then the size of the PDU is
// in the range 1 to 127 bytes and the length1 field contains the overall PDU length
// (the length2 field is not present in this case).
length1 = (byte)(totalLength);
length2 = 0;
RdpbcgrEncoder.EncodeStructure(fpHeaderData, length1);
}
if (context.RdpEncryptionLevel == EncryptionLevel.ENCRYPTION_LEVEL_FIPS)
{
RdpbcgrEncoder.EncodeStructure(fpHeaderData, fipsInformation);
}
// encryptionFlags (2 bits): A higher 2-bit field containing the flags
// that describe the cryptographic parameters of the PDU.
if (((fpInputHeader.actionCode >> 6) & (int)encryptionFlags_Values.FASTPATH_INPUT_ENCRYPTED)
== (int)encryptionFlags_Values.FASTPATH_INPUT_ENCRYPTED)
{
RdpbcgrEncoder.EncodeBytes(fpHeaderData, dataSignature);
}
if ((fpInputHeader.actionCode & (0x0F << 2)) == 0)
{
RdpbcgrEncoder.EncodeStructure(fpHeaderData, numberEvents);
}
return fpHeaderData.ToArray();
}