Nmap Development mailing list archives

Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July)


From: David Fifield <david () bamsoftware com>
Date: Fri, 20 Jul 2012 09:56:51 -0700

On Fri, Jul 20, 2012 at 12:50:03PM -0400, Patrick Donnelly wrote:
If the table is going to be an ordered dictionary, the above can't be
done within a table constructor as the table keys are set before the
metamethods are set. I think this is just as reasonable:

-- Convert a cert (which is a kind of userdata object) into a normal Lua table.
local function to_table(cert)
    local ordict = stdnse.script_output.ordered_dictionary()
        ordict.subject = cert.subject,
        ordict.issuer = cert.issuer,
        ordict.pubkey = cert.pubkey,
        ordict.validity = cert.validity,
        ordict.md5 = stdnse.tohex(cert:digest("md5")),
        ordict.sha1 = stdnse.tohex(cert:digest("sha1")),
        -- ordict.pem = cert.pem,
end

The ordered dictionary detail can be hidden away if we encourage the
use of some function for constructing output tables (all script output
tables should be ordered dictionaries?).

The above looks great to me. I would prefer not to add new strings like
"ordered_dictionary" dictionary to a script author's cognitive load. I'm
trying to think how to make it easier... I suggested having a global
preexisting "output" ordered table that could be assigned into, but that
is also quite magical. Maybe something easier like
        local output = nmap.output_table()
(Even if an ordered table is a generally useful data structure, I don't
think we should force people to think about the orderedness just to ask
for a table to assign into.)

David Fifield
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/


Current thread: