From 8084465e13ee600c733b709059dfbaa753603674 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 4 Aug 2017 23:23:51 +0200 Subject: Rename file to b64file --- file/names.go | 72 ----------------------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 file/names.go (limited to 'file/names.go') diff --git a/file/names.go b/file/names.go deleted file mode 100644 index f893294..0000000 --- a/file/names.go +++ /dev/null @@ -1,72 +0,0 @@ -package file - -import ( - "errors" - "os" - "path" - "path/filepath" - "strings" -) - -var ErrNames = errors.New("please use naming scheme of keyname.pub and keyname.sec") - -const ( - extPub = ".pub" - extSec = ".sec" - extSig = ".sig" - verifyWith = "verify with " -) - -func splitNameExt(fname string) (string, string) { - _, file := path.Split(fname) - ext := filepath.Ext(file) - return file[:len(file)-len(ext)], ext -} - -func ValidateNames(pubFile, secFile string) error { - pubName, pubExt := splitNameExt(pubFile) - secName, secExt := splitNameExt(secFile) - if pubExt != extPub || secExt != extSec || pubName != secName { - return ErrNames - } - return nil -} - -func PubName(secFile string) string { - ext := filepath.Ext(secFile) - return filepath.Base(secFile[:len(ext)-1] + extPub) -} - -func SigName(msgFile string) string { - return msgFile + extSig -} - -func PubFile(comment string) string { - if strings.HasPrefix(comment, verifyWith) { - file := comment[len(verifyWith):] - if strings.HasSuffix(file, extPub) { - return FindFile(file) - } - } - return "" -} - -func VerifyWith(secFile string) string { - return verifyWith + PubName(secFile) -} - -var safePath = []string{ - "/etc/signify", - "$HOME/.signify", -} - -// FindFile locates keys in safe path. Falls back to current dir. -func FindFile(fname string) string { - for _, v := range safePath { - p := path.Join(os.Expand(v, os.Getenv), fname) - if _, err := os.Stat(p); err == nil { - return p - } - } - return fname -} -- cgit v1.2.3