コード例 #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 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
}