AaltoTLS.HandshakeLayer.Protocol.HandshakeStream.ReadUInt24 C# (CSharp) Метод

ReadUInt24() публичный Метод

public ReadUInt24 ( ) : UInt32
Результат System.UInt32
        public UInt32 ReadUInt24()
        {
            byte[] idata;
            try {
                idata = _reader.ReadBytes(3);
                if (idata.Length != 3) {
                    throw new EndOfStreamException();
                }
            } catch (Exception) {
                throw new AlertException(AlertDescription.IllegalParameter,
                                         "Error reading UInt24 in HandshakeStream");
            }

            byte[] odata = new byte[4];
            Array.Copy(idata, 0, odata, odata.Length-idata.Length, idata.Length);
            if (BitConverter.IsLittleEndian) {
                Array.Reverse(odata);
            }
            return BitConverter.ToUInt32(odata, 0);
        }

Usage Example

Пример #1
0
        protected override void DecodeDataBytes(ProtocolVersion version, byte[] data)
        {
            CertificateList.Clear();

            MemoryStream    memStream   = new MemoryStream(data);
            HandshakeStream stream      = new HandshakeStream(memStream);
            int             certsLength = (int)stream.ReadUInt24();

            int readBytes = 0;

            while (readBytes < certsLength)
            {
                int    certLength = (int)stream.ReadUInt24();
                byte[] certBytes  = stream.ReadBytes(certLength);
                readBytes += 3 + certLength;

                CertificateList.Add(new X509Certificate(certBytes));
            }
            if (readBytes != certsLength)
            {
                throw new AlertException(AlertDescription.IllegalParameter,
                                         "Certificate total length doesn't match contents");
            }
            stream.ConfirmEndOfStream();
        }
All Usage Examples Of AaltoTLS.HandshakeLayer.Protocol.HandshakeStream::ReadUInt24