xref: /minix3/crypto/external/bsd/netpgp/dist/src/hkpclient/hkpclient.lua (revision ebfedea0ce5bbe81e252ddf32d732e40fb633fae)
1*ebfedea0SLionel Sambuc#! /usr/bin/env lua
2*ebfedea0SLionel Sambuc
3*ebfedea0SLionel Sambuc--
4*ebfedea0SLionel Sambuc-- Copyright (c) 2010 The NetBSD Foundation, Inc.
5*ebfedea0SLionel Sambuc-- All rights reserved.
6*ebfedea0SLionel Sambuc--
7*ebfedea0SLionel Sambuc-- This code is derived from software contributed to The NetBSD Foundation
8*ebfedea0SLionel Sambuc-- by Alistair Crooks (agc@netbsd.org)
9*ebfedea0SLionel Sambuc--
10*ebfedea0SLionel Sambuc-- Redistribution and use in source and binary forms, with or without
11*ebfedea0SLionel Sambuc-- modification, are permitted provided that the following conditions
12*ebfedea0SLionel Sambuc-- are met:
13*ebfedea0SLionel Sambuc-- 1. Redistributions of source code must retain the above copyright
14*ebfedea0SLionel Sambuc--    notice, this list of conditions and the following disclaimer.
15*ebfedea0SLionel Sambuc-- 2. Redistributions in binary form must reproduce the above copyright
16*ebfedea0SLionel Sambuc--    notice, this list of conditions and the following disclaimer in the
17*ebfedea0SLionel Sambuc--    documentation and/or other materials provided with the distribution.
18*ebfedea0SLionel Sambuc--
19*ebfedea0SLionel Sambuc-- THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*ebfedea0SLionel Sambuc-- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*ebfedea0SLionel Sambuc-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*ebfedea0SLionel Sambuc-- PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*ebfedea0SLionel Sambuc-- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*ebfedea0SLionel Sambuc-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*ebfedea0SLionel Sambuc-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*ebfedea0SLionel Sambuc-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*ebfedea0SLionel Sambuc-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*ebfedea0SLionel Sambuc-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*ebfedea0SLionel Sambuc-- POSSIBILITY OF SUCH DAMAGE.
30*ebfedea0SLionel Sambuc--
31*ebfedea0SLionel Sambuc
32*ebfedea0SLionel Sambuc-- a short HKP client
33*ebfedea0SLionel Sambuc
34*ebfedea0SLionel Sambucrequire("cURL")
35*ebfedea0SLionel Sambuc
36*ebfedea0SLionel Sambuc-- command line args
37*ebfedea0SLionel Sambucdofile "optparse.lua"
38*ebfedea0SLionel Sambuc
39*ebfedea0SLionel Sambucopt = OptionParser{usage="%prog [options] file", version="20100226"}
40*ebfedea0SLionel Sambuc
41*ebfedea0SLionel Sambucopt.add_option{"-V", "--version", action="store_true", dest="version",
42*ebfedea0SLionel Sambuc			help="--version"}
43*ebfedea0SLionel Sambucopt.add_option{"-m", "--mr", action="store_true", dest="mr", help="-m"}
44*ebfedea0SLionel Sambucopt.add_option{"-o", "--op", action="store", dest="op", help="-o op"}
45*ebfedea0SLionel Sambucopt.add_option{"-p", "--port", action="store", dest="port", help="-p port"}
46*ebfedea0SLionel Sambucopt.add_option{"-s", "--server", action="store", dest="server", help="-s server"}
47*ebfedea0SLionel Sambuc
48*ebfedea0SLionel Sambuc-- parse command line args
49*ebfedea0SLionel Sambucoptions,args = opt.parse_args()
50*ebfedea0SLionel Sambuc
51*ebfedea0SLionel Sambuc-- set defaults
52*ebfedea0SLionel Sambuclocal server = options.server or "pgp.mit.edu"
53*ebfedea0SLionel Sambuclocal port = options.port or 11371
54*ebfedea0SLionel Sambuclocal op = options.op or "get"
55*ebfedea0SLionel Sambuclocal mr = ""
56*ebfedea0SLionel Sambucif options.mr then mr = "&options=mr" end
57*ebfedea0SLionel Sambuc
58*ebfedea0SLionel Sambuc-- get output stream
59*ebfedea0SLionel Sambucf = io.output()
60*ebfedea0SLionel Sambuc
61*ebfedea0SLionel Sambucc = cURL.easy_init()
62*ebfedea0SLionel Sambuc
63*ebfedea0SLionel Sambuc-- setup url
64*ebfedea0SLionel Sambucc:setopt_url("http://" .. server .. ":" .. port ..
65*ebfedea0SLionel Sambuc	"/pks/lookup?op=" .. op .. "&search=" .. args[1] .. mr)
66*ebfedea0SLionel Sambuc
67*ebfedea0SLionel Sambuc-- perform, invokes callbacks
68*ebfedea0SLionel Sambucc:perform({writefunction = function(str)
69*ebfedea0SLionel Sambuc				f:write(str)
70*ebfedea0SLionel Sambuc			     end})
71*ebfedea0SLionel Sambuc
72*ebfedea0SLionel Sambuc-- close output file
73*ebfedea0SLionel Sambucf:close()
74*ebfedea0SLionel Sambuc
75