func LoadLocalProfile(name, configDir string) (sk *[64]byte, profile *Profile, err error) {
	if configDir == "" {
		configDir = defaultConfigDir
	}
	path := filepath.Join(configDir, filename(name))
	if _, err = os.Stat(path); err != nil {
		return
	}
	sk = new([64]byte)
	infSk, err := os.Stat(filepath.Join(path, "sk"))
	if err != nil {
		return nil, nil, err
	}
	if !infSk.Mode().IsRegular() {
		return nil, nil, fmt.Errorf("%s is not a regular file", infSk.Name())
	}
	if infSk.Mode().Perm()&077 != 0 {
		return nil, nil, fmt.Errorf("%s is unprotected", infSk.Name())
	}
	skData, err := ioutil.ReadFile(filepath.Join(path, infSk.Name()))
	if err != nil {
		return nil, nil, err
	}
	if len(skData) != 64 {
		return nil, nil, fmt.Errorf("malformed secret key (expected %d bytes, got %d)", 64, len(skData))
	}
	copy(sk[:], skData)
	infProfile, err := os.Stat(filepath.Join(path, "profile"))
	if err != nil {
		return nil, nil, err
	}
	if !infProfile.Mode().IsRegular() {
		return nil, nil, fmt.Errorf("%s is not a regular file", infProfile.Name())
	}
	if infProfile.Mode().Perm()&077 != 0 {
		return nil, nil, fmt.Errorf("%s is unprotected", infProfile.Name())
	}
	profileData, err := ioutil.ReadFile(filepath.Join(path, infProfile.Name()))
	if err != nil {
		return
	}
	profile = new(Profile)
	err = proto.Unmarshal(profileData, profile)
	return
}
LoadLocalProfile returns the secret key and the profile that are locally
known to be correspond to name. This information is not guaranteed to be
current -- if a fresh profile is needed, use client.Lookup instead.
package dnmgr
import (
	"gopkg.in/gcfg.v1"
	"fmt"
	dnmc "github.com/andres-erbsen/dename/client"
	. "github.com/andres-erbsen/dename/protocol"
	"github.com/gogo/protobuf/proto"
	"io/ioutil"
	"os"
	"path/filepath"
	"time"
)
var ErrExist = os.ErrExist
var defaultConfigDir = filepath.Join(os.Getenv("HOME"), ".config", "dename")
func dirAndClient(configDir string, client *dnmc.Client) (string, *dnmc.Client, error) {
	if configDir == "" {
		configDir = defaultConfigDir
	}
	if client == nil {
		clientCfg := new(dnmc.Config)
		err := gcfg.ReadFileInto(clientCfg, filepath.Join(configDir, "authorities.cfg"))
		if os.IsNotExist(err) {
			clientCfg = nil
		} else if err != nil {
			return "", nil, err
		}
		client, err = dnmc.NewClient(clientCfg, nil, nil)
		if err != nil {
			return "", nil, err
		}
	}
	return configDir, client, nil
}
func filename(s string) string {
	return s  
}
func Register(sk *[64]byte, profile *Profile, name string, invite []byte, configDir string, client *dnmc.Client) error {
	configDir, client, err := dirAndClient(configDir, client)
	if err != nil {
		return fmt.Errorf("failed to load config file: %v", err)
	}
	path := filepath.Join(configDir, filename(name))
	if _, err := os.Stat(path); err == nil {
		return ErrExist
	}
	if err = os.MkdirAll(path, 0700); err != nil {
		return err
	}
	if err = ioutil.WriteFile(filepath.Join(path, "sk"), sk[:], 0600); err != nil {
		return err
	}
	profileAlready, err := client.Lookup(name)
	if err != nil && !dnmc.IsErrOutOfDate(err) {
		return fmt.Errorf("lookup failed: %s\n", err)
	} else if profileAlready != nil && !dnmc.IsErrOutOfDate(err) {
		return fmt.Errorf("name already used")
	}
	err = client.Register(sk, name, profile, invite)
	if err != nil {
		return err
	}
	return ioutil.WriteFile(filepath.Join(path, "profile"), PBEncode(profile), 0600)
}