private TS_UD_SC_SEC1 ParseTsUdScSec1(byte[] data, ref int currentIndex)
{
TS_UD_SC_SEC1 secData = new TS_UD_SC_SEC1();
// reserve the start index
int startIndex = currentIndex;
// TS_UD_SC_SEC1: header
secData.header.type = (TS_UD_HEADER_type_Values)ParseUInt16(data, ref currentIndex, false);
secData.header.length = ParseUInt16(data, ref currentIndex, false);
// caculate the end index
int dataEndIndex = secData.header.length + startIndex;
// TS_UD_SC_SEC1: encryptionMethod
secData.encryptionMethod = (EncryptionMethods)ParseUInt32(data, ref currentIndex, false);
// TS_UD_SC_SEC1: encryptionLevel
secData.encryptionLevel = (EncryptionLevel)ParseUInt32(data, ref currentIndex, false);
// TS_UD_SC_SEC1: optional data fields (which can be present/absent)
if (currentIndex < dataEndIndex)
{
// TS_UD_SC_SEC1: serverRandomLen (present)
secData.serverRandomLen = new UInt32Class(ParseUInt32(data, ref currentIndex, false));
// TS_UD_SC_SEC1: serverCertLen (present)
secData.serverCertLen = new UInt32Class(ParseUInt32(data, ref currentIndex, false));
// TS_UD_SC_SEC1: serverRandom (present)
secData.serverRandom = GetBytes(data, ref currentIndex, (int)secData.serverRandomLen.actualData);
// TS_UD_SC_SEC1: serverCertificate (present)
secData.serverCertificate = new SERVER_CERTIFICATE();
// TS_UD_SC_SEC1: serverCertificate: dwVersion
secData.serverCertificate.dwVersion =
(SERVER_CERTIFICATE_dwVersion_Values)ParseUInt32(data, ref currentIndex, false);
// TS_UD_SC_SEC1: serverCertificate: certData
if (SERVER_CERTIFICATE_dwVersion_Values.CERT_CHAIN_VERSION_1 == secData.serverCertificate.dwVersion)
{
// proprietary server certificate
secData.serverCertificate.certData = ParseProprietaryServerCertificate(data, ref currentIndex);
}
else
{
// X509 certificate chain
secData.serverCertificate.certData =
ParseX509CertificateChain(data, ref currentIndex, (dataEndIndex - currentIndex));
}
}
else
{
// TS_UD_SC_SEC1: serverRandomLen (absent)
secData.serverRandomLen = null;
// TS_UD_SC_SEC1: serverCertLen (absent)
secData.serverCertLen = null;
// TS_UD_SC_SEC1: serverRandom (absent)
secData.serverRandom = null;
// TS_UD_SC_SEC1: serverCertificate (absent)
secData.serverCertificate = null;
}
return secData;
}