# 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 base64
import hashlib
import re
from hashlib import sha1, sha256, pbkdf2_hmac
from binascii import b2a_hex, unhexlify, b2a_base64, hexlify
from ....util import state, scram
from ....util.asyncexc import AsynchronousException
from ...http.exceptions import HTTPStatusError
        final_msg = "scram handshaketoken=%s,data=%s" % (
            self._handshake_token,
            client_final_base64,
        )

        try:
            self._session._get(
                "%s/ui" % self._login_uri,
                callback=self._validate_server_token,
                headers={"Authorization": final_msg},
                exclude_cookies=True,
                exclude_headers=True,
                api=False,
            )

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

    def _validate_server_token(self, response):
        try:
            server_response = response.headers["Authentication-Info"]
            tab_response = server_response.split(",")
            self._auth_token = scram.regex_after_equal(tab_response[0])
            self._key = scram.regex_after_equal(tab_response[1])
            self._auth = "Bearer authToken=%s" % self._auth_token
            self._state_machine.login_done(
                result={"header": {b"Authorization": self._auth}, "key": self._key}
            )

        except Exception as e:

# 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/skyspark_scram.py
import fysom
import hmac
import base64
import hashlib
import re
from hashlib import sha1, sha256, pbkdf2_hmac
from binascii import b2a_hex, unhexlify, b2a_base64, hexlify
from ....util import state, scram
from ....util.asyncexc import AsynchronousException
from ...http.exceptions import HTTPStatusError

        final_msg = "scram handshaketoken=%s,data=%s" % (
            self._handshake_token,
            client_final_base64,
        )

        try:
            self._session._get(
                "%s/ui" % self._login_uri,
                callback=self._validate_server_token,
                headers={"Authorization": final_msg},
                exclude_cookies=True,
                exclude_headers=True,
                api=False,
            )

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

    def _validate_server_token(self, response):
        try:
            server_response = response.headers["Authentication-Info"]
            tab_response = server_response.split(",")
            self._auth_token = scram.regex_after_equal(tab_response[0])
            self._key = scram.regex_after_equal(tab_response[1])
            self._auth = "Bearer authToken=%s" % self._auth_token
            self._state_machine.login_done(
                result={"header": {b"Authorization": self._auth}, "key": self._key}
            )

        except Exception as e:

            self._state_machine.exception(result=AsynchronousException())