コード例 #1
0
        public static bool TryParse(MemoryCursor cursor, out Certificate result)
        {
            result = new Certificate();

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

            var body = HandshakeLength.SliceBytes(cursor);

            using var bodyContext = body.SetCursor(cursor);

            CertificateContext.SkipBytes(cursor);

            var payloadBytes = ByteVector.SliceVectorBytes(cursor, 0..ByteVector.MaxUInt24);

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

            result = new Certificate(payloadBytes);

            return(true);
        }
コード例 #2
0
        public static bool TryParse(MemoryCursor cursor, out CertificateVerify result)
        {
            result = new CertificateVerify();

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

            var body = HandshakeLength.SliceBytes(cursor);

            using var bodyContext = body.SetCursor(cursor);

            var scheme    = SignatureScheme.Parse(cursor);
            var signature = ByteVector.SliceVectorBytes(cursor, 0..ushort.MaxValue);

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

            result = new CertificateVerify(scheme, signature);

            return(true);
        }
コード例 #3
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);
            }
        }