from __future__ import annotations

import base64


def b64u_encode(blob: bytes) -> str:
    """
    Encode raw bytes into a URL-safe Base64 string without padding.

    Args:
        blob: Input bytes.

    Returns:
        URL-safe Base64 string (with `=` padding removed).

    Example:
        >>> b64u_encode(b'hi')
        'aGk'
    """
    return base64.urlsafe_b64encode(blob).rstrip(b"=").decode("ascii")


def b64u_decode(string: str) -> bytes:
    """
    Decode a URL-safe Base64 string, accepting missing padding.

    Args:
        string: Base64-URL string (ASCII).

    Returns:
        Decoded raw bytes.

    Example:
        >>> b64u_decode('aGk') == b'hi'
        True
    """
    blob = string.encode("ascii")
    return base64.urlsafe_b64decode(blob + b"=" * (-len(blob) % 4))
