public void TestPasswordMessageCreateMd5()
        {
            var salt = new byte[] { 0x77, 0x16, 0x3e, 0xe3 };

            var authMessage = new AuthenticationMessage {
                AuthenticationMessageType = AuthenticationMessageType.MD5Password,
                DataBuffer = salt
            };

            var state = PostgresClientState.CreateDefault();

            var connectionString = new PostgresConnectionString(
                PostgresServerInformation.FakeConnectionString);

            var passwordMessage = PasswordMessage
                                  .CreateMd5(authMessage, state, connectionString);

            const string expectedHash = "md583ce447ce89d7e4e943205ff8f82f76a";

            try
            {
                var actualHash = Encoding.ASCII.GetString(
                    passwordMessage.Password, 0,
                    passwordMessage.PasswordLength);
                Assert.AreEqual(0x23, passwordMessage.PasswordLength);
                Assert.AreEqual(expectedHash, actualHash);
            }
            finally
            {
                authMessage.TryDispose();
                passwordMessage.TryDispose();
            }
        }
        private void Authenticate(AuthenticationMessage authenticationMessage)
        {
            PasswordMessage passwordMessage;

            switch (authenticationMessage.AuthenticationMessageType)
            {
            case AuthenticationMessageType.MD5Password:
                passwordMessage = PasswordMessage.CreateMd5(
                    authenticationMessage, ClientState,
                    PostgresConnectionString);
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          nameof(authenticationMessage.AuthenticationMessageType),
                          authenticationMessage.AuthenticationMessageType,
                          "Authentication method not supported.");
            }

            using (passwordMessage)
            {
                WriteMessage(passwordMessage);
            }
        }