From a3e526f9b89aa52c21cf8da02a5ddf6682795b1b Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 1 May 2017 17:28:38 +0200 Subject: Names --- main.go | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 6d57343..4471418 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,10 @@ package main import ( - "errors" "flag" "fmt" "io/ioutil" "log" - "path/filepath" "dim13.org/signify/ask" "dim13.org/signify/file" @@ -38,10 +36,6 @@ var ( gzip = flag.Bool("z", false, "Sign and verify gzip archives") ) -var ( - ErrNamingScheme = errors.New("please use naming scheme of keyname.pub and keyname.sec") -) - func main() { flag.Parse() @@ -64,8 +58,8 @@ func main() { } func Generate(pubFile, secFile, comment string, nopass bool) error { - if !NamingScheme(pubFile, secFile) { - return ErrNamingScheme + if err := file.Names(pubFile, secFile); err != nil { + return err } pubKey, encKey, err := signify.NewKey() @@ -174,7 +168,7 @@ func Sign(msgFile, secFile string, embed bool) error { return err } sigfile := &file.Block{ - Comment: fmt.Sprintf("verify with %s", ToPub(secFile)), // TODO replace .sec with .pub + Comment: fmt.Sprintf("verify with %s", file.PubName(secFile)), Bytes: sigRaw, } if embed { @@ -201,16 +195,3 @@ func Verify(msgFile, pubFile string) error { log.Println("Signature Verfied") return nil } - -func NamingScheme(pubFile, secFile string) bool { - pubFile = filepath.Base(pubFile) - secFile = filepath.Base(secFile) - pubExt := filepath.Ext(pubFile) - secExt := filepath.Ext(secFile) - return pubExt == ".pub" && secExt == ".sec" && pubFile[:len(pubExt)-1] == secFile[:len(secExt)-1] -} - -func ToPub(secFile string) string { - ext := filepath.Ext(secFile) - return filepath.Base(secFile[:len(ext)-1] + ".pub") -} -- cgit v1.2.3