import base64


def hexstring_to_b64(hexstring, as_str=False):
    """
    Convert a hexstring to base64.
    :param str hexstring: A hex string as a `str` object.
    :param bool as_str: Whether to return the result as a `str` object.
    :return: The base64 representation of the hexstring as a bytestring
        or `str` object, depending on :param:`bool`.
    """
    result = base64.b64encode(bytes.fromhex(hexstring))
    if as_str:
        result = result.decode()
    return result