/// <summary> /// Reads this object in from an array, returning how many bytes were read, or 0 if there is an error or not enough data /// </summary> /// <param name="bData"></param> /// <param name="nStartAt"></param> /// <returns></returns> public uint ReadFromArray(byte[] bData, int nStartAt) { uint nReadSoFar = 0; if (bData.Length < (nStartAt + 35)) { return(0); } Version = ByteHelper.ReadUshortBigEndian(bData, (int)(nStartAt + nReadSoFar)); nReadSoFar += 2; nReadSoFar += RandomStruct.ReadFromArray(bData, (int)(nStartAt + nReadSoFar)); SessionIDLength = bData[nStartAt + nReadSoFar]; nReadSoFar += 1; if (SessionIDLength > 0) { if (bData.Length < (nStartAt + nReadSoFar + SessionIDLength)) { return(0); } this.SessionID = ByteHelper.ReadByteArray(bData, (int)(nStartAt + nReadSoFar), (int)SessionIDLength); nReadSoFar += SessionIDLength; } CipherSuite = (CipherSuite)ByteHelper.ReadUshortBigEndian(bData, (int)(nStartAt + nReadSoFar)); nReadSoFar += 2; CompressionMethod = (CompressionMethod)ByteHelper.ReadByte(bData, (int)(nStartAt + nReadSoFar)); nReadSoFar += 1; return(nReadSoFar); }
/// <summary> /// Reads this object in from an array, returning how many bytes were read, or 0 if there is an error or not enough data /// </summary> /// <param name="bData"></param> /// <param name="nStartAt"></param> /// <returns></returns> public uint ReadFromArray(byte[] bData, int nStartAt) { int nRead = 0; CertificateTypes.Clear(); CertificateAuthorities.Clear(); int nCertificateTypes = ByteHelper.ReadByte(bData, nStartAt + nRead); nRead += 1; for (int i = 0; i < nCertificateTypes; i++) { CertificateType type = (CertificateType)ByteHelper.ReadByte(bData, nStartAt + nRead); nRead += 1; CertificateTypes.Add(type); } DistinguishedNamesLength = ByteHelper.ReadUshortBigEndian(bData, nStartAt + nRead); nRead += 2; if (DistinguishedNamesLength > 0) { int nLeft = DistinguishedNamesLength; while (nLeft > 0) { int nNextDNLen = ByteHelper.ReadUshortBigEndian(bData, (nStartAt + nRead)); nRead += 2; byte[] bNextDN = ByteHelper.ReadByteArray(bData, nStartAt + nRead, nNextDNLen); nRead += nNextDNLen; CertificateAuthorities.Add(bNextDN); nLeft -= (nNextDNLen + 2); } } return((uint)nRead); }
/// <summary> /// Reads this object in from an array, returning how many bytes were read, or 0 if there is an error or not enough data /// </summary> /// <param name="bData"></param> /// <param name="nStartAt"></param> /// <returns></returns> public uint ReadFromArray(byte[] bData, int nStartAt) { CipherSuites.Clear(); CompressionMethods.Clear(); uint nReadSoFar = 0; if (bData.Length < (nStartAt + 35)) { return(0); } Version = ByteHelper.ReadUshortBigEndian(bData, (int)(nStartAt + nReadSoFar)); nReadSoFar += 2; nReadSoFar += RandomStruct.ReadFromArray(bData, (int)(nStartAt + nReadSoFar)); SessionIDLength = bData[nStartAt + nReadSoFar]; nReadSoFar += 1; if (SessionIDLength > 0) { if (bData.Length < (nStartAt + nReadSoFar + SessionIDLength)) { return(0); } this.SessionID = ByteHelper.ReadByteArray(bData, (int)(nStartAt + nReadSoFar), (int)SessionIDLength); nReadSoFar += SessionIDLength; } if (bData.Length < (nStartAt + nReadSoFar + 2)) { return(0); } CipherSuitesLength = ByteHelper.ReadUshortBigEndian(bData, (int)(nStartAt + nReadSoFar)); nReadSoFar += 2; if (CipherSuitesLength > 0) { if (bData.Length < (nStartAt + nReadSoFar + CipherSuitesLength)) { return(0); } for (int i = 0; i < CipherSuitesLength / 2; i++) { CipherSuite nNextCipherSuite = (CipherSuite)ByteHelper.ReadUshortBigEndian(bData, (int)(nStartAt + nReadSoFar)); nReadSoFar += 2; CipherSuites.Add(nNextCipherSuite); } } if (bData.Length < (nStartAt + nReadSoFar + 2)) { return(0); } CompressionMethodsLength = ByteHelper.ReadByte(bData, (int)(nStartAt + nReadSoFar)); nReadSoFar += 1; if (CompressionMethodsLength > 0) { if (bData.Length < (nStartAt + nReadSoFar + CompressionMethodsLength)) { return(0); } for (int i = 0; i < CipherSuitesLength / 2; i++) { CompressionMethod bNextCompressionMethod = (CompressionMethod)ByteHelper.ReadByte(bData, (int)(nStartAt + nReadSoFar)); nReadSoFar += 1; CompressionMethods.Add(bNextCompressionMethod); } } return(nReadSoFar); }