示例#1
0
文件: cmd.go 项目: jsipprell/crypt
func getEncrypted(key, keyring string, store backend.Store) ([]byte, error) {
	var (
		value    []byte
		passring keyctl.Keyring
		pkr      prompt.PassphraseKeyring
	)
	kr, err := os.Open(secretKeyring)
	if err != nil {
		return value, err
	}
	defer kr.Close()
	data, err := store.Get(key)
	if err != nil {
		return value, err
	}
	if passring, err = SessionKeyring(); err == nil {
		pkr = prompt.PassphraseKeyring{Keyring: passring}
	}

	if passring != nil {
		pkr.Prompt = prompt.NewPrompter(prompt.PassphrasePrompt)
		value, err = secconf.DecodeVia(data, kr, pkr)
	} else {
		value, err = secconf.Decode(data, kr)
	}
	if err != nil {
		return value, err
	}
	return value, err

}
示例#2
0
文件: cmd.go 项目: jsipprell/crypt
func listPlain(key string, store backend.Store) (backend.KVPairs, error) {
	data, err := store.List(key)
	if err != nil {
		return nil, err
	}
	return data, err
}
示例#3
0
文件: cmd.go 项目: jsipprell/crypt
func listEncrypted(key, keyring string, store backend.Store) (backend.KVPairs, error) {
	var (
		passring keyctl.Keyring
		pkr      prompt.PassphraseKeyring
	)
	kr, err := os.Open(secretKeyring)
	if err != nil {
		return nil, err
	}
	defer kr.Close()

	data, err := store.List(key)
	if err != nil {
		return nil, err
	}
	if passring, err = SessionKeyring(); err == nil {
		pkr = prompt.PassphraseKeyring{Keyring: passring}
		pkr.Prompt = prompt.NewPrompter(prompt.PassphrasePrompt)
	}
	for i, kv := range data {
		if passring != nil {
			data[i].Value, err = secconf.DecodeVia(kv.Value, kr, pkr)
		} else {
			data[i].Value, err = secconf.Decode(kv.Value, kr)
		}
		kr.Seek(0, 0)
		if err != nil {
			return nil, err
		}
	}
	return data, err
}
示例#4
0
文件: cmd.go 项目: jsipprell/crypt
func getPlain(key string, store backend.Store) ([]byte, error) {
	var value []byte
	data, err := store.Get(key)
	if err != nil {
		return value, err
	}
	return data, err
}
示例#5
0
文件: cmd.go 项目: jsipprell/crypt
func setEncrypted(key, keyring string, d []byte, store backend.Store, keySelector pubkeyFilter) error {
	kr, err := os.Open(keyring)
	if err != nil {
		return err
	}
	defer kr.Close()
	secureValue, err := secconf.EncodeWith(d, kr, keySelector)
	if err != nil {
		return err
	}
	err = store.Set(key, secureValue)
	return err
}
示例#6
0
文件: cmd.go 项目: jsipprell/crypt
func setPlain(key string, store backend.Store, d []byte) error {
	err := store.Set(key, d)
	return err

}