aboutsummaryrefslogtreecommitdiff
path: root/file
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-05-03 13:46:14 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-05-03 13:46:14 +0200
commitf352ef2392daf85ce0fc7429c31e89fb69dffa91 (patch)
tree6fa54a012d268b1240a45a628afeaaf28ed8502a /file
parent370b8645dc0e6c98b502264d1fb6c8bbda2b6ce4 (diff)
const exts
Diffstat (limited to 'file')
-rw-r--r--file/names.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/file/names.go b/file/names.go
index 0d749c5..9d3e23b 100644
--- a/file/names.go
+++ b/file/names.go
@@ -11,6 +11,12 @@ import (
var ErrNames = errors.New("please use naming scheme of keyname.pub and keyname.sec")
+const (
+ PubExt = ".pub"
+ EncExt = ".enc"
+ SigExt = ".sig"
+)
+
func splitNameExt(fname string) (string, string) {
fname = filepath.Base(fname)
ext := filepath.Ext(fname)
@@ -20,7 +26,7 @@ func splitNameExt(fname string) (string, string) {
func Names(pubFile, encFile string) error {
pubName, pubExt := splitNameExt(pubFile)
encName, encExt := splitNameExt(encFile)
- if pubExt != ".pub" || encExt != ".sec" || pubName != encName {
+ if pubExt != PubExt || encExt != SigExt || pubName != encName {
return ErrNames
}
return nil
@@ -28,11 +34,11 @@ func Names(pubFile, encFile string) error {
func PubName(encFile string) string {
ext := filepath.Ext(encFile)
- return filepath.Base(encFile[:len(ext)-1] + ".pub")
+ return filepath.Base(encFile[:len(ext)-1] + PubExt)
}
func SigName(msgFile string) string {
- return msgFile + ".sig"
+ return msgFile + SigExt
}
const verifyWith = "verify with "
@@ -40,7 +46,7 @@ const verifyWith = "verify with "
func PubFile(comment string) (string, bool) {
if strings.HasPrefix(comment, verifyWith) {
file := comment[len(verifyWith):]
- if strings.HasSuffix(file, ".pub") {
+ if strings.HasSuffix(file, PubExt) {
return FindFile(file), true
}
}