Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/external/bsd/netpgp/dist/src/hkpclient add the script...



details:   https://anonhg.NetBSD.org/src/rev/8ad23038d4a2
branches:  trunk
changeset: 752552:8ad23038d4a2
user:      agc <agc%NetBSD.org@localhost>
date:      Mon Mar 01 07:52:21 2010 +0000

description:
add the scripts used to test the hkpd.

fwiw, the hkp client script is - essentially - 7 lines of lua, using
libcurl for the http transport.

diffstat:

 crypto/external/bsd/netpgp/dist/src/hkpclient/hkpclient.lua |   74 +++++++
 crypto/external/bsd/netpgp/dist/src/hkpclient/optparse.lua  |  123 ++++++++++++
 crypto/external/bsd/netpgp/dist/src/hkpclient/tst           |   21 ++
 3 files changed, 218 insertions(+), 0 deletions(-)

diffs (230 lines):

diff -r 504f64feca58 -r 8ad23038d4a2 crypto/external/bsd/netpgp/dist/src/hkpclient/hkpclient.lua
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/hkpclient/hkpclient.lua       Mon Mar 01 07:52:21 2010 +0000
@@ -0,0 +1,74 @@
+#! /usr/bin/env lua
+
+--
+-- Copyright (c) 2010 The NetBSD Foundation, Inc.
+-- All rights reserved.
+--
+-- This code is derived from software contributed to The NetBSD Foundation
+-- by Alistair Crooks (agc%netbsd.org@localhost)
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+-- 1. Redistributions of source code must retain the above copyright
+--    notice, this list of conditions and the following disclaimer.
+-- 2. Redistributions in binary form must reproduce the above copyright
+--    notice, this list of conditions and the following disclaimer in the
+--    documentation and/or other materials provided with the distribution.
+--
+-- THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+-- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+-- PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+-- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+-- POSSIBILITY OF SUCH DAMAGE.
+--
+
+-- a short HKP client
+
+require("cURL")
+
+-- command line args
+dofile "optparse.lua"
+
+opt = OptionParser{usage="%prog [options] file", version="20100226"}
+
+opt.add_option{"-V", "--version", action="store_true", dest="version",
+                       help="--version"}
+opt.add_option{"-m", "--mr", action="store_true", dest="mr", help="-m"}
+opt.add_option{"-o", "--op", action="store", dest="op", help="-o op"}
+opt.add_option{"-p", "--port", action="store", dest="port", help="-p port"}
+opt.add_option{"-s", "--server", action="store", dest="server", help="-s server"}
+
+-- parse command line args
+options,args = opt.parse_args()
+
+-- set defaults
+local server = options.server or "pgp.mit.edu"
+local port = options.port or 11371
+local op = options.op or "get"
+local mr = ""
+if options.mr then mr = "&options=mr" end
+
+-- get output stream
+f = io.output()
+
+c = cURL.easy_init()
+
+-- setup url
+c:setopt_url("http://"; .. server .. ":" .. port ..
+       "/pks/lookup?op=" .. op .. "&search=" .. args[1] .. mr)
+
+-- perform, invokes callbacks
+c:perform({writefunction = function(str) 
+                               f:write(str)
+                            end})
+
+-- close output file
+f:close()
+
diff -r 504f64feca58 -r 8ad23038d4a2 crypto/external/bsd/netpgp/dist/src/hkpclient/optparse.lua
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/hkpclient/optparse.lua        Mon Mar 01 07:52:21 2010 +0000
@@ -0,0 +1,123 @@
+-- Lua command line option parser.
+-- Interface based on Pythons optparse.
+-- http://docs.python.org/lib/module-optparse.html
+-- (c) 2008 David Manura, Licensed under the same terms as Lua (MIT license)
+--
+-- To be used like this:                                                                  
+-- t={usage="<some usage message>", version="<version string>"}                           
+-- op=OptionParser(t)                                                                     
+-- op=add_option{"<opt>", action=<action>, dest=<dest>, help="<help message for this option>"}
+--
+-- with :
+--   <opt> the option string to be used (can be anything, if one letter opt, then should be -x val, more letters: -xy=val )
+--   <action> one of
+--   - store: store in options as key, val                                                  
+--   - store_true: stores key, true                                                         
+--   - store_false: stores key, false
+--   <dest> is the key under which the option is saved
+--                                      
+-- options,args = op.parse_args()
+--
+-- now options is the table of options (key, val) and args is the table with non-option arguments.
+-- You can use op.fail(message) for failing and op.print_help() for printing the usage as you like.
+
+function OptionParser(t)
+  local usage = t.usage
+  local version = t.version
+
+  local o = {}
+  local option_descriptions = {}
+  local option_of = {}
+
+  function o.fail(s) -- extension
+    io.stderr:write(s .. '\n')
+    os.exit(1)
+  end
+
+  function o.add_option(optdesc)
+    option_descriptions[#option_descriptions+1] = optdesc
+    for _,v in ipairs(optdesc) do
+      option_of[v] = optdesc
+    end
+  end
+  function o.parse_args()
+    -- expand options (e.g. "--input=file" -> "--input", "file")
+    local arg = {unpack(arg)}
+    for i=#arg,1,-1 do local v = arg[i]
+      local flag, val = v:match('^(%-%-%w+)=(.*)')
+      if flag then
+        arg[i] = flag
+        table.insert(arg, i+1, val)
+      end
+    end
+
+    local options = {}
+    local args = {}
+    local i = 1
+    while i <= #arg do local v = arg[i]
+      local optdesc = option_of[v]
+      if optdesc then
+        local action = optdesc.action
+        local val
+        if action == 'store' or action == nil then
+          i = i + 1
+          val = arg[i]
+          if not val then o.fail('option requires an argument ' .. v) end
+        elseif action == 'store_true' then
+          val = true
+        elseif action == 'store_false' then
+          val = false
+        end
+        options[optdesc.dest] = val
+      else
+        if v:match('^%-') then o.fail('invalid option ' .. v) end
+        args[#args+1] = v
+      end
+      i = i + 1
+    end
+    if options.help then
+      o.print_help()
+      os.exit()
+    end
+    if options.version then
+      io.stdout:write(t.version .. "\n")
+      os.exit()
+    end
+    return options, args
+  end
+
+  local function flags_str(optdesc)
+    local sflags = {}
+    local action = optdesc.action
+    for _,flag in ipairs(optdesc) do
+      local sflagend
+      if action == nil or action == 'store' then
+        local metavar = optdesc.metavar or optdesc.dest:upper()
+        sflagend = #flag == 2 and ' ' .. metavar
+                              or  '=' .. metavar
+      else
+        sflagend = ''
+      end
+      sflags[#sflags+1] = flag .. sflagend
+    end
+    return table.concat(sflags, ', ')
+  end
+
+  function o.print_help()
+    io.stdout:write("Usage: " .. usage:gsub('%%prog', arg[0]) .. "\n")
+    io.stdout:write("\n")
+    io.stdout:write("Options:\n")
+    for _,optdesc in ipairs(option_descriptions) do
+      io.stdout:write("  " .. flags_str(optdesc) ..
+                      "  " .. optdesc.help .. "\n")
+    end
+  end
+  o.add_option{"--help", action="store_true", dest="help",
+               help="show this help message and exit"}
+  if t.version then
+    o.add_option{"--version", action="store_true", dest="version",
+                 help="output version info."}
+  end
+  return o
+end
+
diff -r 504f64feca58 -r 8ad23038d4a2 crypto/external/bsd/netpgp/dist/src/hkpclient/tst
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/hkpclient/tst Mon Mar 01 07:52:21 2010 +0000
@@ -0,0 +1,21 @@
+#! /bin/sh
+
+host=localhost
+
+while [ $# -gt 0 ]; do
+       case $1 in
+       -h)
+               host=$2
+               shift
+               ;;
+       *)
+               break
+               ;;
+       esac
+       shift
+done
+
+./hkpclient.lua -s ${host} agc%netbsd.org@localhost
+./hkpclient.lua --op index -s ${host} 0xc0596823
+./hkpclient.lua -o index -s ${host} --mr 0xc0596823
+./hkpclient.lua -o index -s ${host} dhklsbcldshjkcdlsjhcvdsljhvcdsljhcvdjlshvcdsc



Home | Main Index | Thread Index | Old Index