From a3e526f9b89aa52c21cf8da02a5ddf6682795b1b Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 1 May 2017 17:28:38 +0200 Subject: Names --- file/names.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 file/names.go (limited to 'file/names.go') diff --git a/file/names.go b/file/names.go new file mode 100644 index 0000000..265117e --- /dev/null +++ b/file/names.go @@ -0,0 +1,24 @@ +package file + +import ( + "errors" + "path/filepath" +) + +var ErrNames = errors.New("please use naming scheme of keyname.pub and keyname.sec") + +func Names(pubFile, secFile string) error { + pubFile = filepath.Base(pubFile) + secFile = filepath.Base(secFile) + pubExt := filepath.Ext(pubFile) + secExt := filepath.Ext(secFile) + if pubExt != ".pub" || secExt != ".sec" || pubFile[:len(pubExt)-1] != secFile[:len(secExt)-1] { + return ErrNames + } + return nil +} + +func PubName(secFile string) string { + ext := filepath.Ext(secFile) + return filepath.Base(secFile[:len(ext)-1] + ".pub") +} -- cgit v1.2.3