aboutsummaryrefslogtreecommitdiff
path: root/file/names.go
blob: 265117e46e13477fab07bc0c5b011eb229fa7055 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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")
}