From 370b8645dc0e6c98b502264d1fb6c8bbda2b6ce4 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 3 May 2017 13:43:18 +0200 Subject: Split name/ext --- file/names.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'file/names.go') diff --git a/file/names.go b/file/names.go index eb6bff8..0d749c5 100644 --- a/file/names.go +++ b/file/names.go @@ -11,12 +11,16 @@ import ( var ErrNames = errors.New("please use naming scheme of keyname.pub and keyname.sec") +func splitNameExt(fname string) (string, string) { + fname = filepath.Base(fname) + ext := filepath.Ext(fname) + return fname[:len(ext)-1], ext +} + func Names(pubFile, encFile string) error { - pubFile = filepath.Base(pubFile) - encFile = filepath.Base(encFile) - pubExt := filepath.Ext(pubFile) - encExt := filepath.Ext(encFile) - if pubExt != ".pub" || encExt != ".sec" || pubFile[:len(pubExt)-1] != encFile[:len(encExt)-1] { + pubName, pubExt := splitNameExt(pubFile) + encName, encExt := splitNameExt(encFile) + if pubExt != ".pub" || encExt != ".sec" || pubName != encName { return ErrNames } return nil -- cgit v1.2.3