# File ../../auditor/lib/kasp_auditor/partial_auditor.rb, line 231
    def check_nsec_loop
      # Follow the loop of NSEC3 records in @nsec_temp_file,
      # and make sure that they present a closed loop.

      return if (@config.denial.nsec) # Need to have NSEC loop sorted canonically if we are to follow it!

      # First, sort the @nsec_temp_file
      
      system("#{Commands.sort} #{@nsec_temp_file} > #{@nsec_temp_file}.tmp")
      system("mv #{@nsec_temp_file}.tmp #{@nsec_temp_file}")
      # Then simply follow it line by line.
      next_name = nil
      last_name = nil
      last_line = nil
      zone_name = @soa.name.to_s.downcase
      first_name = nil
      IO.foreach(@nsec_temp_file) {|line|
        # @TODO@ Do we need to parse the record to get the next owner name?
        if (next_name)
          compare_val = (next_name <=> line.split()[0])
          if (compare_val > 0)
            # last was greater than we expected - we missed an NSEC
            # print an error
            log(LOG_ERR, "Can't follow #{line.split()[3]} loop from #{last_name} to #{next_name}")
          elsif (compare_val < 0)
            # last was less than we expected - we have an extra nsec
            # print an error
            log(LOG_ERR, "#{line.split()[3]} record left after folowing closed loop : #{line.split()[0]}. Was expecting #{next_name}")
          else
            # All OK
          end
        else
          first_name = line.split()[0]
        end
        next_name = get_next(line) + ".#{zone_name}."
        last_name = line.split()[0]
        last_line = line
      }
      # Now make sure that NSEC points back to the first
      if ((next_name != first_name) && last_line)
        log(LOG_ERR, "Can't follow #{last_line.split()[3]} loop from #{last_name} to #{next_name} - found #{first_name}")
      end
    end