func SystemKeypath() (keypath []string) {
	keypath = append(keypath, "/etc/ecfg/keys")
	keypath = append(keypath, "/opt/ejson/keys")
	return
}
SystemKeypath returns the default system-wide locations at which to search
for ecfg keys. /opt/ejson/keys is provided for backwards-compatibility with
ejson.
package ecfg
import (
	"encoding/hex"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"github.com/Shopify/ecfg/pkg/crypto"
	"github.com/Shopify/ecfg/pkg/format"
	"github.com/Shopify/ecfg/pkg/json"
	"github.com/Shopify/ecfg/pkg/toml"
	"github.com/Shopify/ecfg/pkg/yaml"
)
type FileType int
const (
	FileTypeJSON = iota
	FileTypeYAML
	FileTypeTOML
)
func GenerateKeypair() (pub string, priv string, err error) {
	var kp crypto.Keypair
	if err := kp.Generate(); err != nil {
		return "", "", err
	}
	return kp.PublicString(), kp.PrivateString(), nil
}
func EncryptFileInPlace(filePath string, fileType FileType) (int, error) {
	data, err := readFile(filePath)
	if err != nil {
		return -1, err
	}
	fileMode, err := getMode(filePath)
	if err != nil {
		return -1, err
	}
	newdata, err := EncryptData(data, fileType)
	if err != nil {
		return -1, err
	}
	if err := writeFile(filePath, newdata, fileMode); err != nil {
		return -1, err
	}
	return len(newdata), nil
}
func EncryptData(data []byte, fileType FileType) ([]byte, error) {
	fh := handlerForType(fileType)
	var myKP crypto.Keypair
	if err := myKP.Generate(); err != nil {
		return nil, err
	}
	pubkey, err := fh.ExtractPublicKey(data)
	if err != nil {
		return nil, err
	}
	encrypter := myKP.Encrypter(pubkey)
	return fh.TransformScalarValues(data, encrypter.Encrypt)
}
func DecryptFile(filePath string, keypath []string, fileType FileType) ([]byte, error) {
	data, err := readFile(filePath)
	if err != nil {
		return nil, err
	}
	return DecryptData(data, keypath, fileType)
}
func DecryptData(data []byte, keypath []string, fileType FileType) ([]byte, error) {
	fh := handlerForType(fileType)
	pubkey, err := fh.ExtractPublicKey(data)
	if err != nil {
		return nil, err
	}
	privkey, err := findPrivateKey(pubkey, keypath)
	if err != nil {
		return nil, err
	}
	myKP := crypto.Keypair{
		Public:  pubkey,
		Private: privkey,
	}
	decrypter := myKP.Decrypter()
	return fh.TransformScalarValues(data, decrypter.Decrypt)
}
func DefaultKeypath() (keypath []string) {
	for _, elem := range UserKeypath() {
		keypath = append(keypath, elem)
	}
	for _, elem := range SystemKeypath() {
		keypath = append(keypath, elem)
	}
	return
}
func UserKeypath() (keypath []string) {
	if getuid() == 0 {
		return
	}
	xdgConfigHome := getenv("XDG_CONFIG_HOME")
	if xdgConfigHome != "" {
		keypath = append(keypath, filepath.Join(xdgConfigHome, "ecfg", "keys"))
	}
	keypath = append(keypath, filepath.Join(getenv("HOME"), ".ecfg", "keys"))
	return
}