Ejemplo n.º 1
0
        public static bool TryParse(MemoryCursor cursor, out ServerHello result)
        {
            result = new ServerHello();

            if (!HandshakeType.TrySlice(cursor, HandshakeType.ServerHello))
            {
                return(false);
            }

            using (HandshakeLength.SliceBytes(cursor).SetCursor(cursor))
            {
                if (!ProtocolVersion.TrySlice(cursor, ProtocolVersion.Tls12))
                {
                    throw new EncodingException();
                }

                var random    = HandshakeRandom.Parse(cursor);
                var sessionId = SessionId.Parse(cursor);
                var cipher    = Cipher.Parse(cursor);

                if (!CompressionMethod.TrySliceEmptyValue(cursor))
                {
                    throw new EncodingException();
                }

                var payload = ByteVector.SliceVectorBytes(cursor, 0..ushort.MaxValue);

                if (!cursor.IsEnd())
                {
                    throw new EncodingException();
                }

                result = new ServerHello(random, cipher, sessionId, payload);

                return(true);
            }
        }