# Path: jose/jws.py
# def sign(payload, key, headers=None, algorithm=ALGORITHMS.HS256):
# def verify(token, key, algorithms, verify=True):
# def get_unverified_header(token):
# def get_unverified_headers(token):
# def get_unverified_claims(token):
# def _encode_header(algorithm, additional_headers=None):
# def _encode_payload(payload):
# def _sign_header_and_claims(encoded_header, encoded_claims, algorithm, key):
# def _load(jwt):
# def _sig_matches_keys(keys, signing_input, signature, alg):
# def _get_keys(key):
# def _verify_signature(signing_input, header, signature, key="", algorithms=None):
# 
# Path: jose/jwt.py
# def encode(claims, key, algorithm=ALGORITHMS.HS256, headers=None, access_token=None):
# def decode(token, key, algorithms=None, options=None, audience=None, issuer=None, subject=None, access_token=None):
# def get_unverified_header(token):
# def get_unverified_headers(token):
# def get_unverified_claims(token):
# def _validate_iat(claims):
# def _validate_nbf(claims, leeway=0):
# def _validate_exp(claims, leeway=0):
# def _validate_aud(claims, audience=None):
# def _validate_iss(claims, issuer=None):
# def _validate_sub(claims, subject=None):
# def _validate_jti(claims):
# def _validate_at_hash(claims, access_token, algorithm):
# def _validate_claims(claims, audience=None, issuer=None, subject=None, algorithm=None, access_token=None, options=None):
# 
# Path: jose/exceptions.py
# class JWTError(JOSEError):
#     pass


import base64
import json
import pytest
from datetime import datetime, timedelta
from jose import jws, jwt
from jose.exceptions import JWTError
        from collections import OrderedDict
        from jose.utils import base64url_decode
        headers2 = OrderedDict(
            (
                ("another_key", "another_value"),
                ("kid", "my-key-id"),
            )
        )
        encoded2 = jwt.encode(claims, key, algorithm="HS256", headers=headers2)
        encoded_headers2 = encoded2.split(".", 1)[0]

        assert encoded_headers1 == encoded_headers2

        # manually decode header to compare it to known good
        decoded_headers1 = base64url_decode(encoded_headers1.encode("utf-8"))
        assert decoded_headers1 == b"""{"alg":"HS256","another_key":"another_value","kid":"my-key-id","typ":"JWT"}"""

    def test_encode(self, claims, key):

        expected = (
            ("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9" ".eyJhIjoiYiJ9" ".xNtk2S0CNbCBZX_f67pFgGRugaP1xi2ICfet3nwOSxw"),
            ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" ".eyJhIjoiYiJ9" ".jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8"),
        )

        encoded = jwt.encode(claims, key)

        assert encoded in expected

    def test_decode(self, claims, key):

        token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" ".eyJhIjoiYiJ9" ".jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8"


# Path: jose/jws.py
# def sign(payload, key, headers=None, algorithm=ALGORITHMS.HS256):
# def verify(token, key, algorithms, verify=True):
# def get_unverified_header(token):
# def get_unverified_headers(token):
# def get_unverified_claims(token):
# def _encode_header(algorithm, additional_headers=None):
# def _encode_payload(payload):
# def _sign_header_and_claims(encoded_header, encoded_claims, algorithm, key):
# def _load(jwt):
# def _sig_matches_keys(keys, signing_input, signature, alg):
# def _get_keys(key):
# def _verify_signature(signing_input, header, signature, key="", algorithms=None):
# 
# Path: jose/jwt.py
# def encode(claims, key, algorithm=ALGORITHMS.HS256, headers=None, access_token=None):
# def decode(token, key, algorithms=None, options=None, audience=None, issuer=None, subject=None, access_token=None):
# def get_unverified_header(token):
# def get_unverified_headers(token):
# def get_unverified_claims(token):
# def _validate_iat(claims):
# def _validate_nbf(claims, leeway=0):
# def _validate_exp(claims, leeway=0):
# def _validate_aud(claims, audience=None):
# def _validate_iss(claims, issuer=None):
# def _validate_sub(claims, subject=None):
# def _validate_jti(claims):
# def _validate_at_hash(claims, access_token, algorithm):
# def _validate_claims(claims, audience=None, issuer=None, subject=None, algorithm=None, access_token=None, options=None):
# 
# Path: jose/exceptions.py
# class JWTError(JOSEError):
#     pass


# Path: tests/test_jwt.py
import base64
import json
import pytest
from datetime import datetime, timedelta
from jose import jws, jwt
from jose.exceptions import JWTError
        from collections import OrderedDict
        from jose.utils import base64url_decode

        headers2 = OrderedDict(
            (
                ("another_key", "another_value"),
                ("kid", "my-key-id"),
            )
        )
        encoded2 = jwt.encode(claims, key, algorithm="HS256", headers=headers2)
        encoded_headers2 = encoded2.split(".", 1)[0]

        assert encoded_headers1 == encoded_headers2

        # manually decode header to compare it to known good
        decoded_headers1 = base64url_decode(encoded_headers1.encode("utf-8"))
        assert decoded_headers1 == b"""{"alg":"HS256","another_key":"another_value","kid":"my-key-id","typ":"JWT"}"""

    def test_encode(self, claims, key):

        expected = (
            ("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9" ".eyJhIjoiYiJ9" ".xNtk2S0CNbCBZX_f67pFgGRugaP1xi2ICfet3nwOSxw"),
            ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" ".eyJhIjoiYiJ9" ".jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8"),
        )

        encoded = jwt.encode(claims, key)

        assert encoded in expected

    def test_decode(self, claims, key):

        token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" ".eyJhIjoiYiJ9" ".jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8"


        decoded = jwt.decode(token, key)