import re


def parse_keyslots_luks2(luks_dump):
    """Lists the used keyslots in a LUKS2 device. These may or may not be
    bound to clevis.
    Return: <used keyslots> <error>"""

    if not luks_dump:
        return None, {"msg": "Empty dump provided"}

    # This is the pattern we are looking for:
    #   0: clevis
    #         Keyslot:  3
    pattern = r"^\s+(\d+): luks2$"
    match = re.findall(pattern, luks_dump, re.MULTILINE | re.DOTALL)
    if not match:
        errmsg = "parse_keyslots_luks2: no used key slots"
        return None, {"msg": errmsg}
    return match, None