示例#1
0
        /// <summary>
        /// Parse a Handshake protocol header from wire format
        /// </summary>
        /// <returns>True if we successfully decode a handshake header. Otherwise false</returns>
        public static bool Parse(out Handshake header, ByteSpan span)
        {
            header = new Handshake();

            if (span.Length < Size)
            {
                return(false);
            }

            header.MessageType     = (HandshakeType)span[0];
            header.Length          = span.ReadBigEndian24(1);
            header.MessageSequence = span.ReadBigEndian16(4);
            header.FragmentOffset  = span.ReadBigEndian24(6);
            header.FragmentLength  = span.ReadBigEndian24(9);
            return(true);
        }
示例#2
0
        /// <summary>
        /// Parse a Handshake Certificate payload from wire format
        /// </summary>
        /// <returns>True if we successfully decode the Certificate message. Otherwise false</returns>
        public static bool Parse(out X509Certificate2 certificate, ByteSpan span)
        {
            certificate = null;
            if (span.Length < 6)
            {
                return(false);
            }

            uint totalSize = span.ReadBigEndian24();

            span = span.Slice(3);

            if (span.Length < totalSize)
            {
                return(false);
            }

            uint certificateSize = span.ReadBigEndian24();

            span = span.Slice(3);
            if (span.Length < certificateSize)
            {
                return(false);
            }

            byte[] rawData = new byte[certificateSize];
            span.CopyTo(rawData, 0);
            try
            {
                certificate = new X509Certificate2(rawData);
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }