Nmap Development mailing list archives
Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July)
From: Patrick Donnelly <batrick () batbytes com>
Date: Fri, 20 Jul 2012 12:50:03 -0400
On Fri, Jul 20, 2012 at 11:00 AM, David Fifield <david () bamsoftware com> wrote:
On Fri, Jul 20, 2012 at 10:54:32AM -0400, Patrick Donnelly wrote:On Thu, Jul 19, 2012 at 7:08 PM, David Fifield <david () bamsoftware com> wrote:I can deal with the field names being lower-case and identifier-like; maybe people will even prefer them that way. But the fact that "md5" and "sha1" are not on adjacent lines is galling. Maybe a special kind of table format that keeps order (i.e., an array of name-value pairs)? That would seem to require a higher-level function with which to set output values.You can get an ordered dictionary in Lua with some metamethod magic:Right, thanks for that. I don't doubt that it can be done. I'm asking if it's a reasonable model for setting script output.
I think so, yes.
I'm attaching a copy of ssl-cert.nse modified to return a structured
table. It's the same one used to create the most recent output example
on the wiki page. This, I think, is about as nice as setting structured
output is going to get, and it would be nice if this method could
provide nice ordered output.
-- Convert a cert (which is a kind of userdata object) into a normal Lua table.
local function to_table(cert)
return {
subject = cert.subject,
issuer = cert.issuer,
pubkey = cert.pubkey,
validity = cert.validity,
md5 = stdnse.tohex(cert:digest("md5")),
sha1 = stdnse.tohex(cert:digest("sha1")),
-- pem = cert.pem,
}
end
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?).
--
- Patrick Donnelly
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/
Current thread:
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 19)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 19)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) Patrick Donnelly (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) Patrick Donnelly (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 20)
- Re: [RFC][patch] XML structured script output (Nmap-script-XML as of 15 July) David Fifield (Jul 20)
- Re: XML structured script output (storing results per script instance) David Fifield (Jul 31)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Jul 31)
- Re: XML structured script output (storing results per script instance) David Fifield (Jul 31)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Aug 01)
- Re: XML structured script output (storing results per script instance) Daniel Miller (Aug 01)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Aug 01)
- Re: XML structured script output (storing results per script instance) Daniel Miller (Aug 02)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Aug 03)
- Re: XML structured script output (storing results per script instance) Patrick Donnelly (Jul 31)
