source: vendor/netbsd/8/src/crypto/external/bsd/netpgp/dist/bindings/lua/netpgp.lua @ 298

Last change on this file since 298 was 298, checked in by bouyer, 6 years ago

Load . into vendor/netbsd/8.

  • Property svn:executable set to *
File size: 3.5 KB
Line 
1#! /usr/bin/env lua
2
3--
4-- Copyright (c) 2009 The NetBSD Foundation, Inc.
5-- All rights reserved.
6--
7-- This code is derived from software contributed to The NetBSD Foundation
8-- by Alistair Crooks (agc@netbsd.org)
9--
10-- Redistribution and use in source and binary forms, with or without
11-- modification, are permitted provided that the following conditions
12-- are met:
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.
18--
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.
30--
31
32-- command line args
33dofile "optparse.lua"
34
35opt = OptionParser{usage="%prog [options] file", version="20090711"}                           
36
37opt.add_option{"-s", "--sign", action="store_true", dest="sign", help="--sign [--detached] [--armour] file"}
38opt.add_option{"-v", "--verify", action="store_true", dest="verify", help="--verify [--armour] file"}
39opt.add_option{"-e", "--encrypt", action="store_true", dest="encrypt", help="--encrypt [--armour] file"}
40opt.add_option{"-d", "--decrypt", action="store_true", dest="decrypt", help="--decrypt [--armour] file"}
41opt.add_option{"-h", "--homedir", action="store", dest="homedir", help="--homedir directory"}
42opt.add_option{"-o", "--output", action="store", dest="output", help="--output file"}
43opt.add_option{"-a", "--armour", action="store_true", dest="armour", help="--armour"}
44opt.add_option{"-D", "--detached", action="store_true", dest="detached", help="--detached"}
45
46-- caller lua script
47local extension = ".so"
48f = io.open("libluanetpgp.dylib", "r")
49if f then
50        extension = ".dylib"
51        io.close(f)
52end
53glupkg = package.loadlib("libluanetpgp" .. extension, "luaopen_netpgp")
54netpgp = glupkg()
55
56-- initialise
57pgp = netpgp.new()
58
59-- parse command line args
60options,args = opt.parse_args()
61
62-- set defaults
63local output = options.output or ""
64local armour = "binary"
65if options.armour then
66        armour = "armour"
67end
68local detached = "attached"
69if options.detached then
70        detached = "detached"
71end
72if options.homedir then
73        netpgp.homedir(pgp, options.homedir)
74end
75
76-- initialise everything
77netpgp.init(pgp)
78
79local i
80for i = 1, #args do
81        if options.encrypt then
82                -- encrypt a file
83                netpgp.encrypt_file(pgp, args[1], output, armour)
84                os.execute("ls -l " .. args[1] .. ".gpg")
85        end
86        if options.decrypt then
87                -- decrypt file
88                netpgp.decrypt_file(pgp, args[1], output, armour)
89        end
90        if options.sign then
91                -- detached signature
92                netpgp.sign_file(pgp, args[1], output, armour, detached)
93                os.execute("ls -l " .. args[1] .. ".sig")
94        end
95        if options.verify then
96                -- verification of detached signature
97                netpgp.verify_file(pgp, args[1], armour)
98        end
99end
Note: See TracBrowser for help on using the repository browser.