aboutsummaryrefslogtreecommitdiff
path: root/file
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-05-01 17:40:34 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-05-01 17:40:34 +0200
commit860801a7170c962928be0ffe6b93c42417cb06c2 (patch)
tree261b5008eb0a4d6fb0462948b16831d7c64aace9 /file
parentc18b790725200baaffbcfdb32907f3cd1b6d9be1 (diff)
Verify with
Diffstat (limited to 'file')
-rw-r--r--file/names.go13
-rw-r--r--file/names_test.go20
2 files changed, 33 insertions, 0 deletions
diff --git a/file/names.go b/file/names.go
index f8bfa58..6846097 100644
--- a/file/names.go
+++ b/file/names.go
@@ -3,6 +3,7 @@ package file
import (
"errors"
"path/filepath"
+ "strings"
)
var ErrNames = errors.New("please use naming scheme of keyname.pub and keyname.sec")
@@ -22,3 +23,15 @@ func PubName(encFile string) string {
ext := filepath.Ext(encFile)
return filepath.Base(encFile[:len(ext)-1] + ".pub")
}
+
+const verifyWith = "verify with "
+
+func PubFile(comment string) (string, bool) {
+ if strings.HasPrefix(comment, verifyWith) {
+ file := comment[len(verifyWith):]
+ if strings.HasSuffix(file, ".pub") {
+ return file, true
+ }
+ }
+ return "", false
+}
diff --git a/file/names_test.go b/file/names_test.go
index 5c9941a..d57d6ee 100644
--- a/file/names_test.go
+++ b/file/names_test.go
@@ -22,3 +22,23 @@ func TestNames(t *testing.T) {
})
}
}
+
+func TestVerify(t *testing.T) {
+ testCases := []struct {
+ comment string
+ file string
+ }{
+ {"verify with key.pub", "key.pub"},
+ {"verify with s p a c e s.pub", "s p a c e s.pub"},
+ {"verify with key.sec", ""},
+ {"whatever", ""},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.comment, func(t *testing.T) {
+ file, _ := PubFile(tc.comment)
+ if file != tc.file {
+ t.Errorf("got %v, want %v", file, tc.file)
+ }
+ })
+ }
+}