From f352ef2392daf85ce0fc7429c31e89fb69dffa91 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 3 May 2017 13:46:14 +0200 Subject: const exts --- file/names.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'file') 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 } } -- cgit v1.2.3