# Path: pyhaystack/util/state.py
# @property
# def state(self):
#     """
#     Return the current state machine's state.
#     """
#     return self._state_machine.current
# 
# Path: pyhaystack/util/scram.py
# def get_nonce():
# def get_nonce_16():
# def _hash_sha256(client_key, algorithm):
# def salted_password(salt, iterations, algorithm_name, password):
# def salted_password_2(salt, iterations, algorithm_name, password):
# def base64_no_padding(s):
# def regex_after_equal(s):
# def _xor(s1, s2):
# 
# Path: pyhaystack/util/asyncexc.py
# class AsynchronousException(object):
#     def __init__(self):
#         self._exc_info = exc_info()
# 
#     def reraise(self):
#         reraise(*self._exc_info)
# 
# Path: pyhaystack/client/http/exceptions.py
# class HTTPStatusError(HTTPBaseError):
#     """
#     Error class to represent a returned failed status from the host.
#     """
# 
#     def __init__(self, message, status, headers=None, body=None):
#         self.headers = headers
#         self.body = body
#         self.status = status
#         super(HTTPStatusError, self).__init__(message, status)


import fysom
import hmac
import re
from hashlib import sha256
from binascii import unhexlify, b2a_base64, hexlify
from ....util import state, scram
from ....util.asyncexc import AsynchronousException
from ...http.exceptions import HTTPStatusError
                )

        except Exception as e:
            self._state_machine.exception(result=AsynchronousException())

    def _do_validate_login(self, event):
        """
        We need to send another request to the server to validate the login
        """
        try:
            self._session._post(
                "%s/j_security_check" % self._login_uri,
                body=None,
                callback=self._on_validate_login,
                headers={"Content-Type": "application/x-niagara-login-support"},
                api=False,
            )
        except:
            self._state_machine.exception(result=AsynchronousException())

    def _on_validate_login(self, response):
        """
        Retrieve the response and set authenticated status
        """
        try:
            if isinstance(response, AsynchronousException):
                response.reraise()
            if response.status_code == 200:
                self._state_machine.login_done(result={"authenticated": True})
            else:

# Path: pyhaystack/util/state.py
# @property
# def state(self):
#     """
#     Return the current state machine's state.
#     """
#     return self._state_machine.current
# 
# Path: pyhaystack/util/scram.py
# def get_nonce():
# def get_nonce_16():
# def _hash_sha256(client_key, algorithm):
# def salted_password(salt, iterations, algorithm_name, password):
# def salted_password_2(salt, iterations, algorithm_name, password):
# def base64_no_padding(s):
# def regex_after_equal(s):
# def _xor(s1, s2):
# 
# Path: pyhaystack/util/asyncexc.py
# class AsynchronousException(object):
#     def __init__(self):
#         self._exc_info = exc_info()
# 
#     def reraise(self):
#         reraise(*self._exc_info)
# 
# Path: pyhaystack/client/http/exceptions.py
# class HTTPStatusError(HTTPBaseError):
#     """
#     Error class to represent a returned failed status from the host.
#     """
# 
#     def __init__(self, message, status, headers=None, body=None):
#         self.headers = headers
#         self.body = body
#         self.status = status
#         super(HTTPStatusError, self).__init__(message, status)


# Path: pyhaystack/client/ops/vendor/niagara_scram.py
import fysom
import hmac
import re
from hashlib import sha256
from binascii import unhexlify, b2a_base64, hexlify
from ....util import state, scram
from ....util.asyncexc import AsynchronousException
from ...http.exceptions import HTTPStatusError

                )

        except Exception as e:
            self._state_machine.exception(result=AsynchronousException())

    def _do_validate_login(self, event):
        """
        We need to send another request to the server to validate the login
        """
        try:
            self._session._post(
                "%s/j_security_check" % self._login_uri,
                body=None,
                callback=self._on_validate_login,
                headers={"Content-Type": "application/x-niagara-login-support"},
                api=False,
            )
        except:
            self._state_machine.exception(result=AsynchronousException())

    def _on_validate_login(self, response):
        """
        Retrieve the response and set authenticated status
        """
        try:
            if isinstance(response, AsynchronousException):
                response.reraise()
            if response.status_code == 200:
                self._state_machine.login_done(result={"authenticated": True})
            else:

                raise HTTPStatusError("Server refused the last message")