示例#1
0
        /// <summary>
        ///     Parse the first server message.
        /// </summary>
        /// <param name="message">Message to parse.</param>
        /// <param name="firstMessage"><see cref="ServerFirstMessage"/> instance of the message.</param>
        /// <returns>true if parsing was successful; otherwise false.</returns>
        public static bool TryParse(string message, out ServerFirstMessage firstMessage)
        {
            firstMessage = new ServerFirstMessage();

            try
            {
                var attributes = ScramAttribute.ParseAll(message);

                if (!attributes.OfType <IterationsAttribute>().Any() ||
                    !attributes.OfType <NonceAttribute>().Any() ||
                    !attributes.OfType <SaltAttribute>().Any())
                {
                    return(false);
                }

                foreach (var attribute in attributes)
                {
                    switch (attribute)
                    {
                    case IterationsAttribute a:
                        firstMessage.Iterations = a;
                        break;

                    case NonceAttribute a:
                        firstMessage.Nonce = a;
                        break;

                    case SaltAttribute a:
                        firstMessage.Salt = a;
                        break;

                    case ErrorAttribute a:
                        return(false);
                    }
                }
            }
            catch (FormatException)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ClientFinalMessage"/> class.
 /// </summary>
 /// <param name="clientFirstMessage">First client message.</param>
 /// <param name="serverFirstMessage">First server message.</param>
 public ClientFinalMessage(ClientFirstMessage clientFirstMessage, ServerFirstMessage serverFirstMessage)
 {
     Channel = new ChannelAttribute(clientFirstMessage.Gs2Header);
     Nonce   = new NonceAttribute(serverFirstMessage.Nonce?.Value);
 }