public static ExtractMessagesResult ExtractMessages(ProtoType type, byte[] buffer)
        {
            ExtractMessagesResult result = new ExtractMessagesResult();

            switch (type)
            {
            case ProtoType.Handshake:
                CreateHandshakeMessages(buffer, result);
                break;

            case ProtoType.ChangeCipherSpec:
                CCSProtocolMessage cMsg = CreateCCSMessage(buffer);
                result.protocolMessages.Add(cMsg);
                break;

            case ProtoType.Alert:
                AlertProtocolMessage aMsg = CreateAlertMessage(buffer);
                result.protocolMessages.Add(aMsg);
                break;

            case ProtoType.ApplicationData:
                ApplicationProtocolMessage apm = CreateAPMessage(buffer);
                result.protocolMessages.Add(apm);
                break;
            }

            return(result);
        }
        private static CCSProtocolMessage CreateCCSMessage(byte[] buffer)
        {
            CCSProtocolMessage cMsg = null;

            try
            {
                cMsg = new CCSProtocolMessage(buffer);
            }
            catch (Exception)
            {
                throw new SslAlertException(AlertLevel.Fatal, AlertDescription.DecodeError);
            }
            return(cMsg);
        }