from typing import Union
import base64


def b64u_decode(
    data: Union[str, bytes],
) -> bytes:
    """
    Decodes a base64url-encoded data.
    :param data: the data to decode.
    :return: the decoded data as bytes.
    """
    if not isinstance(data, bytes):
        if not isinstance(data, str):
            data = str(data)
        data = data.encode("ascii")

    padding_len = len(data) % 4
    if padding_len:
        data = data + b"=" * padding_len

    decoded = base64.urlsafe_b64decode(data)
    return decoded