aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--check.go21
-rw-r--r--generate.go16
-rw-r--r--main.go4
-rw-r--r--sign.go19
-rw-r--r--verify.go23
5 files changed, 40 insertions, 43 deletions
diff --git a/check.go b/check.go
index d30b577..78c1e66 100644
--- a/check.go
+++ b/check.go
@@ -3,26 +3,25 @@ package main
import (
"flag"
"fmt"
- "os"
)
// Usage: signify -C [-q] -p pubkey -x sigfile [file ...]
-func check() error {
- args := flag.NewFlagSet("check", flag.ExitOnError)
+func check(args []string) error {
+ opts := flag.NewFlagSet("check", flag.ExitOnError)
var (
- quiet = args.Bool("q", false, "Quiet mode")
- pubFile = args.String("p", "", "Public key file (required)")
- sigFile = args.String("x", "", "Signature file (required)")
+ quiet = opts.Bool("q", false, "Quiet mode")
+ pubFile = opts.String("p", "", "Public key file (required)")
+ sigFile = opts.String("x", "", "Signature file (required)")
)
- args.Parse(os.Args[2:])
+ opts.Parse(args)
if *pubFile == "" || *sigFile == "" {
- args.Usage()
+ opts.Usage()
return nil
}
- files := make([]string, args.NArg())
- for i := 0; i < args.NArg(); i++ {
- files[i] = args.Arg(i)
+ files := make([]string, opts.NArg())
+ for i := 0; i < opts.NArg(); i++ {
+ files[i] = opts.Arg(i)
}
fmt.Println(files)
_, _, _ = quiet, pubFile, sigFile // TODO
diff --git a/generate.go b/generate.go
index 0b0cf49..52a95f6 100644
--- a/generate.go
+++ b/generate.go
@@ -11,17 +11,17 @@ import (
// Usage: signify -G [-n] [-c comment] -p pubkey -s seckey
-func generate() error {
- args := flag.NewFlagSet("generate", flag.ExitOnError)
+func generate(args []string) error {
+ opts := flag.NewFlagSet("generate", flag.ExitOnError)
var (
- nopass = args.Bool("n", false, "No key passphrase")
- comment = args.String("c", "signify", "Comment")
- pubFile = args.String("p", "", "Public key file (required)")
- encFile = args.String("s", "", "Secret key file (required)")
+ nopass = opts.Bool("n", false, "No key passphrase")
+ comment = opts.String("c", "signify", "Comment")
+ pubFile = opts.String("p", "", "Public key file (required)")
+ encFile = opts.String("s", "", "Secret key file (required)")
)
- args.Parse(os.Args[2:])
+ opts.Parse(args)
if *pubFile == "" || *encFile == "" {
- args.Usage()
+ opts.Usage()
return nil
}
if err := file.CheckNames(*pubFile, *encFile); err != nil {
diff --git a/main.go b/main.go
index b132ba8..e782051 100644
--- a/main.go
+++ b/main.go
@@ -14,7 +14,7 @@ func usage() {
os.Exit(2)
}
-var modes = map[string]func() error{
+var modes = map[string]func([]string) error{
"-C": check,
"-G": generate,
"-S": sign,
@@ -29,7 +29,7 @@ func main() {
if !ok {
usage()
}
- if err := mode(); err != nil {
+ if err := mode(os.Args[2:]); err != nil {
fmt.Println(err)
os.Exit(1)
}
diff --git a/sign.go b/sign.go
index f65adb3..368108f 100644
--- a/sign.go
+++ b/sign.go
@@ -4,7 +4,6 @@ import (
"errors"
"flag"
"io/ioutil"
- "os"
"dim13.org/signify/ask"
"dim13.org/signify/file"
@@ -13,21 +12,21 @@ import (
// Usage: signify -S [-ez] [-x sigfile] -s seckey -m message
-func sign() error {
- args := flag.NewFlagSet("sign", flag.ExitOnError)
+func sign(args []string) error {
+ opts := flag.NewFlagSet("sign", flag.ExitOnError)
var (
- embedded = args.Bool("e", false, "Embed the message")
- zip = args.Bool("z", false, "Sign gzip archive")
- sigFile = args.String("x", "", "Signature file")
- encFile = args.String("s", "", "Secret file (required)")
- msgFile = args.String("m", "", "Message file (required)")
+ embedded = opts.Bool("e", false, "Embed the message")
+ zip = opts.Bool("z", false, "Sign gzip archive")
+ sigFile = opts.String("x", "", "Signature file")
+ encFile = opts.String("s", "", "Secret file (required)")
+ msgFile = opts.String("m", "", "Message file (required)")
)
- args.Parse(os.Args[2:])
+ opts.Parse(args)
if *embedded && *zip {
return errors.New("can't combine -e and -z options")
}
if *encFile == "" || *msgFile == "" {
- args.Usage()
+ opts.Usage()
return nil
}
if *sigFile == "" {
diff --git a/verify.go b/verify.go
index 1e35f23..3ea4fea 100644
--- a/verify.go
+++ b/verify.go
@@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"io/ioutil"
- "os"
"dim13.org/signify/file"
"dim13.org/signify/key"
@@ -13,23 +12,23 @@ import (
// Usage: signify -V [-eqz] [-p pubkey] [-t keytype] [-x sigfile] -m message
-func verify() error {
- args := flag.NewFlagSet("verify", flag.ExitOnError)
+func verify(args []string) error {
+ opts := flag.NewFlagSet("verify", flag.ExitOnError)
var (
- embedded = args.Bool("e", false, "Embed message")
- quiet = args.Bool("q", false, "Quiet mode")
- zip = args.Bool("z", false, "Verify gzip archive")
- pubFile = args.String("p", "", "Public key file")
- keyType = args.String("t", "", "Key type") // TODO
- sigFile = args.String("x", "", "Signature file")
- msgFile = args.String("m", "", "Message file (required)")
+ embedded = opts.Bool("e", false, "Embed message")
+ quiet = opts.Bool("q", false, "Quiet mode")
+ zip = opts.Bool("z", false, "Verify gzip archive")
+ pubFile = opts.String("p", "", "Public key file")
+ keyType = opts.String("t", "", "Key type") // TODO
+ sigFile = opts.String("x", "", "Signature file")
+ msgFile = opts.String("m", "", "Message file (required)")
)
- args.Parse(os.Args[2:])
+ opts.Parse(args)
if *embedded && *zip {
return errors.New("can't combine -e and -z options")
}
if *msgFile == "" {
- args.Usage()
+ opts.Usage()
return nil
}
if *sigFile == "" {