# Path: test/common.py
# def _new_utcnow():
# def _new_now():
# def _new_time():
# def clock_load(utcnow):
# def clock_tick(delta=timedelta()):
# def clock_reset():
# 
# Path: test/jwt_spec.py
# def is_string(obj):
# def _setup(alg, priv_type, pub_type, exp, iat_skew, nbf, jti_size, keyless, expected):
#         def topic(self):
#             def topic(self, topic):
#                 def topic(self, token):
#                 def payload_keys_should_be_as_expected(self, claims):
#                 def payload_values_should_match(self, claims):
#                 def jtis_should_be_unique(self, claims):
#                 def jti_size_should_be_as_expected(self, claims):
#             def header_should_be_as_expected(self, token):
#             def topic(self, topic):
#             def should_fail_to_verify(self, r):
#             def topic(self, topic):
#             def should_verify_as_expected(self, r):
# def setup(algs=algs):
#     class GenerateJWT(Vows.Context): #pylint: disable=unused-variable
#         class ProcessJWT(Vows.Context):
#             class CheckClaims(Vows.Context):
#         class VerifyJWTWithGeneratedKey(Vows.Context):
#         class VerifyJWT(Vows.Context):


from test.common import pub_keys, priv_keys, algs
from test import jwt_spec
from datetime import datetime, timedelta
from subprocess import Popen, PIPE
from calendar import timegm
from threading import Lock
from jwcrypto.common import base64url_decode, json_encode, json_decode
""" test interop with jose for node """

# pylint: disable=wrong-import-order

lock = Lock()

def spawn(cmd, parse_json):
    """ run node command """
    #pylint: disable=E1101
    with lock:
        p = Popen(["node", "--unhandled-rejections=strict", "-e", "fixtures=require('./test/fixtures');" + cmd], #pylint: disable=consider-using-with
                  stdout=PIPE, stderr=PIPE)
        (stdout, stderr) = p.communicate()
    stdout = stdout.decode('utf-8')
    stderr = stderr.decode('utf-8')
    if p.returncode == 0:
        return json_decode(stdout) if parse_json else stdout
    raise Exception(stderr if stderr else ('exited with {}'.format(p.returncode)))
    #pylint: enable=E1101

#pylint: disable=W0621
def generate(alg):
    """ return function which can generate token using jose """

# Path: test/common.py
# def _new_utcnow():
# def _new_now():
# def _new_time():
# def clock_load(utcnow):
# def clock_tick(delta=timedelta()):
# def clock_reset():
# 
# Path: test/jwt_spec.py
# def is_string(obj):
# def _setup(alg, priv_type, pub_type, exp, iat_skew, nbf, jti_size, keyless, expected):
#         def topic(self):
#             def topic(self, topic):
#                 def topic(self, token):
#                 def payload_keys_should_be_as_expected(self, claims):
#                 def payload_values_should_match(self, claims):
#                 def jtis_should_be_unique(self, claims):
#                 def jti_size_should_be_as_expected(self, claims):
#             def header_should_be_as_expected(self, token):
#             def topic(self, topic):
#             def should_fail_to_verify(self, r):
#             def topic(self, topic):
#             def should_verify_as_expected(self, r):
# def setup(algs=algs):
#     class GenerateJWT(Vows.Context): #pylint: disable=unused-variable
#         class ProcessJWT(Vows.Context):
#             class CheckClaims(Vows.Context):
#         class VerifyJWTWithGeneratedKey(Vows.Context):
#         class VerifyJWT(Vows.Context):


# Path: test/jose_interop_vows.py
from test.common import pub_keys, priv_keys, algs
from test import jwt_spec
from datetime import datetime, timedelta
from subprocess import Popen, PIPE
from calendar import timegm
from threading import Lock
from jwcrypto.common import base64url_decode, json_encode, json_decode

""" test interop with jose for node """

# pylint: disable=wrong-import-order

lock = Lock()

def spawn(cmd, parse_json):
    """ run node command """
    #pylint: disable=E1101
    with lock:
        p = Popen(["node", "--unhandled-rejections=strict", "-e", "fixtures=require('./test/fixtures');" + cmd], #pylint: disable=consider-using-with
                  stdout=PIPE, stderr=PIPE)
        (stdout, stderr) = p.communicate()
    stdout = stdout.decode('utf-8')
    stderr = stderr.decode('utf-8')
    if p.returncode == 0:
        return json_decode(stdout) if parse_json else stdout
    raise Exception(stderr if stderr else ('exited with {}'.format(p.returncode)))
    #pylint: enable=E1101

#pylint: disable=W0621
def generate(alg):
    """ return function which can generate token using jose """

    key = priv_keys[alg]['python-jwt']