# Path: jose/jwk.py
# def get_key(algorithm):
# def register_key(algorithm, key_class):
# def construct(key_data, algorithm=None):
# 
# Path: jose/backends/base.py
# class Key:
#     """
#     A simple interface for implementing JWK keys.
#     """
# 
#     def __init__(self, key, algorithm):
#         pass
# 
#     def sign(self, msg):
#         raise NotImplementedError()
# 
#     def verify(self, msg, sig):
#         raise NotImplementedError()
# 
#     def public_key(self):
#         raise NotImplementedError()
# 
#     def to_pem(self):
#         raise NotImplementedError()
# 
#     def to_dict(self):
#         raise NotImplementedError()
# 
#     def encrypt(self, plain_text, aad=None):
#         """
#         Encrypt the plain text and generate an auth tag if appropriate
# 
#         Args:
#             plain_text (bytes): Data to encrypt
#             aad (bytes, optional): Authenticated Additional Data if key's algorithm supports auth mode
# 
#         Returns:
#             (bytes, bytes, bytes): IV, cipher text, and auth tag
#         """
#         raise NotImplementedError()
# 
#     def decrypt(self, cipher_text, iv=None, aad=None, tag=None):
#         """
#         Decrypt the cipher text and validate the auth tag if present
#         Args:
#             cipher_text (bytes): Cipher text to decrypt
#             iv (bytes): IV if block mode
#             aad (bytes): Additional Authenticated Data to verify if auth mode
#             tag (bytes): Authentication tag if auth mode
# 
#         Returns:
#             bytes: Decrypted value
#         """
#         raise NotImplementedError()
# 
#     def wrap_key(self, key_data):
#         """
#         Wrap the the plain text key data
# 
#         Args:
#             key_data (bytes): Key data to wrap
# 
#         Returns:
#             bytes: Wrapped key
#         """
#         raise NotImplementedError()
# 
#     def unwrap_key(self, wrapped_key):
#         """
#         Unwrap the the wrapped key data
# 
#         Args:
#             wrapped_key (bytes): Wrapped key data to unwrap
# 
#         Returns:
#             bytes: Unwrapped key
#         """
#         raise NotImplementedError()
# 
# Path: jose/constants.py
# ALGORITHMS = Algorithms()
# 
# Path: jose/exceptions.py
# class JWSError(JOSEError):
#     pass
# 
# class JWSSignatureError(JWSError):
#     pass
# 
# Path: jose/utils.py
# def base64url_decode(input):
#     """Helper method to base64url_decode a string.
# 
#     Args:
#         input (str): A base64url_encoded string to decode.
# 
#     """
#     rem = len(input) % 4
# 
#     if rem > 0:
#         input += b"=" * (4 - rem)
# 
#     return base64.urlsafe_b64decode(input)
# 
# def base64url_encode(input):
#     """Helper method to base64url_encode a string.
# 
#     Args:
#         input (str): A base64url_encoded string to encode.
# 
#     """
#     return base64.urlsafe_b64encode(input).replace(b"=", b"")


import binascii
import json
from collections.abc import Iterable, Mapping
from jose import jwk
from jose.backends.base import Key
from jose.constants import ALGORITHMS
from jose.exceptions import JWSError, JWSSignatureError
from jose.utils import base64url_decode, base64url_encode

    return encoded_string.decode("utf-8")


def _load(jwt):
    if isinstance(jwt, str):
        jwt = jwt.encode("utf-8")
    try:
        signing_input, crypto_segment = jwt.rsplit(b".", 1)
        header_segment, claims_segment = signing_input.split(b".", 1)
        header_data = base64url_decode(header_segment)
    except ValueError:
        raise JWSError("Not enough segments")
    except (TypeError, binascii.Error):
        raise JWSError("Invalid header padding")

    try:
        header = json.loads(header_data.decode("utf-8"))
    except ValueError as e:
        raise JWSError("Invalid header string: %s" % e)

    if not isinstance(header, Mapping):
        raise JWSError("Invalid header string: must be a json object")

    try:
        payload = base64url_decode(claims_segment)
    except (TypeError, binascii.Error):
        raise JWSError("Invalid payload padding")

    try:

# Path: jose/jwk.py
# def get_key(algorithm):
# def register_key(algorithm, key_class):
# def construct(key_data, algorithm=None):
# 
# Path: jose/backends/base.py
# class Key:
#     """
#     A simple interface for implementing JWK keys.
#     """
# 
#     def __init__(self, key, algorithm):
#         pass
# 
#     def sign(self, msg):
#         raise NotImplementedError()
# 
#     def verify(self, msg, sig):
#         raise NotImplementedError()
# 
#     def public_key(self):
#         raise NotImplementedError()
# 
#     def to_pem(self):
#         raise NotImplementedError()
# 
#     def to_dict(self):
#         raise NotImplementedError()
# 
#     def encrypt(self, plain_text, aad=None):
#         """
#         Encrypt the plain text and generate an auth tag if appropriate
# 
#         Args:
#             plain_text (bytes): Data to encrypt
#             aad (bytes, optional): Authenticated Additional Data if key's algorithm supports auth mode
# 
#         Returns:
#             (bytes, bytes, bytes): IV, cipher text, and auth tag
#         """
#         raise NotImplementedError()
# 
#     def decrypt(self, cipher_text, iv=None, aad=None, tag=None):
#         """
#         Decrypt the cipher text and validate the auth tag if present
#         Args:
#             cipher_text (bytes): Cipher text to decrypt
#             iv (bytes): IV if block mode
#             aad (bytes): Additional Authenticated Data to verify if auth mode
#             tag (bytes): Authentication tag if auth mode
# 
#         Returns:
#             bytes: Decrypted value
#         """
#         raise NotImplementedError()
# 
#     def wrap_key(self, key_data):
#         """
#         Wrap the the plain text key data
# 
#         Args:
#             key_data (bytes): Key data to wrap
# 
#         Returns:
#             bytes: Wrapped key
#         """
#         raise NotImplementedError()
# 
#     def unwrap_key(self, wrapped_key):
#         """
#         Unwrap the the wrapped key data
# 
#         Args:
#             wrapped_key (bytes): Wrapped key data to unwrap
# 
#         Returns:
#             bytes: Unwrapped key
#         """
#         raise NotImplementedError()
# 
# Path: jose/constants.py
# ALGORITHMS = Algorithms()
# 
# Path: jose/exceptions.py
# class JWSError(JOSEError):
#     pass
# 
# class JWSSignatureError(JWSError):
#     pass
# 
# Path: jose/utils.py
# def base64url_decode(input):
#     """Helper method to base64url_decode a string.
# 
#     Args:
#         input (str): A base64url_encoded string to decode.
# 
#     """
#     rem = len(input) % 4
# 
#     if rem > 0:
#         input += b"=" * (4 - rem)
# 
#     return base64.urlsafe_b64decode(input)
# 
# def base64url_encode(input):
#     """Helper method to base64url_encode a string.
# 
#     Args:
#         input (str): A base64url_encoded string to encode.
# 
#     """
#     return base64.urlsafe_b64encode(input).replace(b"=", b"")


# Path: jose/jws.py
import binascii
import json
from collections.abc import Iterable, Mapping
from jose import jwk
from jose.backends.base import Key
from jose.constants import ALGORITHMS
from jose.exceptions import JWSError, JWSSignatureError
from jose.utils import base64url_decode, base64url_encode


    return encoded_string.decode("utf-8")


def _load(jwt):
    if isinstance(jwt, str):
        jwt = jwt.encode("utf-8")
    try:
        signing_input, crypto_segment = jwt.rsplit(b".", 1)
        header_segment, claims_segment = signing_input.split(b".", 1)
        header_data = base64url_decode(header_segment)
    except ValueError:
        raise JWSError("Not enough segments")
    except (TypeError, binascii.Error):
        raise JWSError("Invalid header padding")

    try:
        header = json.loads(header_data.decode("utf-8"))
    except ValueError as e:
        raise JWSError("Invalid header string: %s" % e)

    if not isinstance(header, Mapping):
        raise JWSError("Invalid header string: must be a json object")

    try:
        payload = base64url_decode(claims_segment)
    except (TypeError, binascii.Error):
        raise JWSError("Invalid payload padding")

    try:

        signature = base64url_decode(crypto_segment)