internal static bool TryParse(byte[] data, BinaryReader reader, out NtlmAuthenticationToken token)
        {
            token = null;
            NtlmNegotiateFlags flags = (NtlmNegotiateFlags)reader.ReadInt32();

            if (!NtlmUtils.ParseString(NtlmNegotiateFlags.Oem, reader,
                                       data, flags.HasFlagSet(NtlmNegotiateFlags.OemDomainSupplied),
                                       out string domain))
            {
                return(false);
            }
            if (!NtlmUtils.ParseString(NtlmNegotiateFlags.Oem, reader,
                                       data, flags.HasFlagSet(NtlmNegotiateFlags.OemWorkstationSupplied),
                                       out string workstation))
            {
                return(false);
            }
            if (!NtlmUtils.TryParse(reader, out Version version))
            {
                return(false);
            }

            token = new NtlmNegotiateAuthenticationToken(data, flags, domain, workstation, version);
            return(true);
        }
        /// <summary>
        /// Try and parse data into an NTLM authentication token.
        /// </summary>
        /// <param name="data">The data to parse.</param>
        /// <param name="token">The NTLM authentication token.</param>
        /// <param name="client">True if this is a token from a client.</param>
        /// <param name="token_count">The token count number.</param>
        /// <returns>True if parsed successfully.</returns>
        internal static bool TryParse(byte[] data, int token_count, bool client, out NtlmAuthenticationToken token)
        {
            token = null;
            if (data.Length < 12)
            {
                return(false);
            }
            if (BinaryEncoding.Instance.GetString(data, 0, 8) != NTLM_MAGIC)
            {
                return(false);
            }
            MemoryStream stm    = new MemoryStream(data);
            BinaryReader reader = new BinaryReader(stm);

            stm.Position = 8;
            NtlmMessageType type = (NtlmMessageType)reader.ReadInt32();

            switch (type)
            {
            case NtlmMessageType.Negotiate:
                return(NtlmNegotiateAuthenticationToken.TryParse(data, reader, out token));

            case NtlmMessageType.Challenge:
                return(NtlmChallengeAuthenticationToken.TryParse(data, reader, out token));

            case NtlmMessageType.Authenticate:
                return(NtlmAuthenticateAuthenticationToken.TryParse(data, reader, out token));

            default:
                return(false);
            }
        }