4 -- Copyright (c) 2009 The NetBSD Foundation, Inc.
5 -- All rights reserved.
7 -- This code is derived from software contributed to The NetBSD Foundation
8 -- by Alistair Crooks (agc@netbsd.org)
10 -- Redistribution and use in source and binary forms, with or without
11 -- modification, are permitted provided that the following conditions
13 -- 1. Redistributions of source code must retain the above copyright
14 -- notice, this list of conditions and the following disclaimer.
15 -- 2. Redistributions in binary form must reproduce the above copyright
16 -- notice, this list of conditions and the following disclaimer in the
17 -- documentation and/or other materials provided with the distribution.
19 -- THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 -- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 -- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 -- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 -- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 -- POSSIBILITY OF SUCH DAMAGE.
35 opt
= OptionParser
{usage
="%prog [options] file", version
="20090711"}
37 opt
.add_option
{"-s", "--sign", action
="store_true", dest
="sign", help
="--sign [--detached] [--armour] file"}
38 opt
.add_option
{"-v", "--verify", action
="store_true", dest
="verify", help
="--verify [--armour] file"}
39 opt
.add_option
{"-e", "--encrypt", action
="store_true", dest
="encrypt", help
="--encrypt [--armour] file"}
40 opt
.add_option
{"-d", "--decrypt", action
="store_true", dest
="decrypt", help
="--decrypt [--armour] file"}
41 opt
.add_option
{"-h", "--homedir", action
="store", dest
="homedir", help
="--homedir directory"}
42 opt
.add_option
{"-o", "--output", action
="store", dest
="output", help
="--output file"}
43 opt
.add_option
{"-a", "--armour", action
="store_true", dest
="armour", help
="--armour"}
44 opt
.add_option
{"-D", "--detached", action
="store_true", dest
="detached", help
="--detached"}
47 local extension
= ".so"
48 f
= io
.open("libluanetpgp.dylib", "r")
53 glupkg
= package
.loadlib("libluanetpgp" .. extension
, "luaopen_netpgp")
59 -- parse command line args
60 options
,args
= opt
.parse_args()
63 local output
= options
.output
or ""
64 local armour
= "binary"
65 if options
.armour
then
68 local detached
= "attached"
69 if options
.detached
then
72 if options
.homedir
then
73 netpgp
.homedir(pgp
, options
.homedir
)
76 -- initialise everything
81 if options
.encrypt
then
83 netpgp
.encrypt_file(pgp
, args
[1], output
, armour
)
84 os
.execute("ls -l " .. args
[1] .. ".gpg")
86 if options
.decrypt
then
88 netpgp
.decrypt_file(pgp
, args
[1], output
, armour
)
92 netpgp
.sign_file(pgp
, args
[1], output
, armour
, detached
)
93 os
.execute("ls -l " .. args
[1] .. ".sig")
95 if options
.verify
then
96 -- verification of detached signature
97 netpgp
.verify_file(pgp
, args
[1], armour
)