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

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

public ReadBytes ( int count ) : byte[]
count int
Результат byte[]
        public byte[] ReadBytes(int count)
        {
            byte[] data;
            try {
                data = _reader.ReadBytes(count);
                if (data.Length != count) {
                    throw new EndOfStreamException();
                }
            } catch (Exception) {
                throw new AlertException(AlertDescription.IllegalParameter,
                                         "Error reading " + count + " bytes of data in HandshakeStream");
            }
            return data;
        }

Usage Example

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

            MemoryStream    memStream = new MemoryStream(data);
            HandshakeStream stream    = new HandshakeStream(memStream);

            int typesLength = stream.ReadUInt8();

            for (int i = 0; i < typesLength; i++)
            {
                CertificateTypes.Add(stream.ReadUInt8());
            }

            if (version.HasSelectableSighash)
            {
                int sighashLength = stream.ReadUInt16();
                if ((sighashLength % 2) != 0)
                {
                    throw new AlertException(AlertDescription.IllegalParameter,
                                             "SianatureAndHashAlgorithms length invalid: " + sighashLength);
                }

                byte[] sighashData = stream.ReadBytes(sighashLength);
                for (int i = 0; i < sighashLength; i += 2)
                {
                    SignatureAndHashAlgorithms.Add((UInt16)((sighashData[i] << 8) | sighashData[i + 1]));
                }
            }

            int authsLength = stream.ReadUInt16();

            byte[] authData = stream.ReadBytes(authsLength);
            stream.ConfirmEndOfStream();

            int position = 0;

            while (position < authData.Length)
            {
                int authLength = (authData[position] << 8) | authData[position + 1];
                position += 2;

                if (position > authData.Length)
                {
                    throw new AlertException(AlertDescription.IllegalParameter,
                                             "Authorities total length doesn't match contents");
                }

                string name = Encoding.ASCII.GetString(authData, position, authLength);
                position += authLength;

                CertificateAuthorities.Add(name);
            }
        }
All Usage Examples Of AaltoTLS.HandshakeLayer.Protocol.HandshakeStream::ReadBytes