# 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
        now = datetime.utcnow()
        return spawn(
            "fixtures.generate({now}, {header}, {claims}, {expires}, {not_before}, {key})".format(
                now=timegm(now.utctimetuple()),
                header=json_encode({'alg': alg}),
                claims=json_encode(claims),
                expires=timegm(((now + lifetime) if lifetime else expires).utctimetuple()),
                not_before=timegm((not_before or now).utctimetuple()),
                key=json_encode(base64url_decode(json_decode(key.export())['k']) if key.is_symmetric else key.export_to_pem(True, None))),
            False)
    return f

def verify(alg):
    """ return function which can verify token using jose """
    key = pub_keys[alg]['python-jwt']
    def f(sjwt, iat_skew=timedelta()):
        """ verify token using jose """
        r = spawn(
            "fixtures.verify({now}, {sjwt}, {iat_skew}, {key}, {alg})".format(
                now=timegm(datetime.utcnow().utctimetuple()),
                sjwt=json_encode(sjwt),
                iat_skew=iat_skew.total_seconds(),
                key=json_encode(base64url_decode(json_decode(key.export())['k']) if key.is_symmetric else key.export_to_pem()),
                alg=json_encode(alg)),
            True)
        return tuple(r)
    return f

for alg in algs:
    priv_keys[alg]['jose'] = generate(alg)

# 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

        now = datetime.utcnow()
        return spawn(
            "fixtures.generate({now}, {header}, {claims}, {expires}, {not_before}, {key})".format(
                now=timegm(now.utctimetuple()),
                header=json_encode({'alg': alg}),
                claims=json_encode(claims),
                expires=timegm(((now + lifetime) if lifetime else expires).utctimetuple()),
                not_before=timegm((not_before or now).utctimetuple()),
                key=json_encode(base64url_decode(json_decode(key.export())['k']) if key.is_symmetric else key.export_to_pem(True, None))),
            False)
    return f

def verify(alg):
    """ return function which can verify token using jose """
    key = pub_keys[alg]['python-jwt']
    def f(sjwt, iat_skew=timedelta()):
        """ verify token using jose """
        r = spawn(
            "fixtures.verify({now}, {sjwt}, {iat_skew}, {key}, {alg})".format(
                now=timegm(datetime.utcnow().utctimetuple()),
                sjwt=json_encode(sjwt),
                iat_skew=iat_skew.total_seconds(),
                key=json_encode(base64url_decode(json_decode(key.export())['k']) if key.is_symmetric else key.export_to_pem()),
                alg=json_encode(alg)),
            True)
        return tuple(r)
    return f

for alg in algs:
    priv_keys[alg]['jose'] = generate(alg)

    pub_keys[alg]['jose'] = verify(alg)