import base64


def base64_decode(encoded):
    """Inverse of `base64_encode`"""
    b_encoded = encoded.encode('ascii', 'surrogateescape')
    s = b''.join(b_encoded.splitlines())
    return base64.b64decode(s, validate=True)