aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-20 00:19:35 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-20 00:19:35 +0200
commit6d9c53c8f8c9561c29c0ce8bce207234d2524fd1 (patch)
tree423a683a229ebaab86b65c89282257ea1ae80dc0 /cmd
parentfb2256e42ec00281e4e5fdbd4035c823c172425b (diff)
Naming Scheme
Diffstat (limited to 'cmd')
-rw-r--r--cmd/signify/main.go17
-rw-r--r--cmd/signify/main_test.go24
2 files changed, 41 insertions, 0 deletions
diff --git a/cmd/signify/main.go b/cmd/signify/main.go
index 9cdb6cd..58706ee 100644
--- a/cmd/signify/main.go
+++ b/cmd/signify/main.go
@@ -1,11 +1,13 @@
package main
import (
+ "errors"
"flag"
"fmt"
"io/ioutil"
"log"
"path"
+ "path/filepath"
"dim13.org/signify"
)
@@ -35,6 +37,10 @@ var (
gzip = flag.Bool("z", false, "Sign and verify gzip archives")
)
+var (
+ ErrNamingScheme = errors.New("please use naming scheme of keyname.pub and keyname.sec")
+)
+
func main() {
flag.Parse()
@@ -61,6 +67,9 @@ func main() {
}
func Generate(pubFile, secFile, comment string, rounds int) error {
+ if !NamingScheme(pubFile, secFile) {
+ return ErrNamingScheme
+ }
pubKey, encKey, err := signify.NewKey()
if err != nil {
return err
@@ -203,3 +212,11 @@ func Verify(msgFile, pubFile string) error {
log.Println("Signature Verfied")
return nil
}
+
+func NamingScheme(pubFile, secFile string) bool {
+ pubFile = filepath.Base(pubFile)
+ secFile = filepath.Base(secFile)
+ pubExt := filepath.Ext(pubFile)
+ secExt := filepath.Ext(secFile)
+ return pubExt == ".pub" && secExt == ".sec" && pubFile[:len(pubExt)] == secFile[:len(secExt)]
+}
diff --git a/cmd/signify/main_test.go b/cmd/signify/main_test.go
new file mode 100644
index 0000000..1e8d0e5
--- /dev/null
+++ b/cmd/signify/main_test.go
@@ -0,0 +1,24 @@
+package main
+
+import "testing"
+
+func TestNamingScheme(t *testing.T) {
+ testCases := []struct {
+ pub, sec string
+ ok bool
+ }{
+ {"key.pub", "key.sec", true},
+ {"testdata/key.pub", "key.sec", true},
+ {"key.pub", "testdata/key.sec", true},
+ {"foo.pub", "bar.sec", false},
+ {"key.foo", "key.bar", false},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.pub+"+"+tc.sec, func(t *testing.T) {
+ ok := NamingScheme(tc.pub, tc.sec)
+ if ok != tc.ok {
+ t.Errorf("got %v, want %v", ok, tc.ok)
+ }
+ })
+ }
+}