def METHOD_NAME(detail_string: Optional[str]) -> HapCredentials:
    """Parse a string representation of HapCredentials."""
    if detail_string is None:
        return NO_CREDENTIALS
    split = detail_string.split(":")
    # Compatibility with "legacy credentials" used by AirPlay where seed is stored
    # as LTSK and identifier as client_id (others are empty).
    if len(split) == 2:
        client_id = binascii.unhexlify(split[0])
        ltsk = binascii.unhexlify(split[1])
        return HapCredentials(b"", ltsk, b"", client_id)
    if len(split) == 4:
        ltpk = binascii.unhexlify(split[0])
        ltsk = binascii.unhexlify(split[1])
        atv_id = binascii.unhexlify(split[2])
        client_id = binascii.unhexlify(split[3])
        return HapCredentials(ltpk, ltsk, atv_id, client_id)
    raise exceptions.InvalidCredentialsError("invalid credentials: " + detail_string)