package main import ( "bufio" "fmt" "os" "strings" ) // decryptEntry resolves an entry's governing Vault key and decrypts its `.gpg` // file through the engine. func decryptEntry(s *store, v *vaultClient, name string) ([]byte, error) { if !s.hasEntry(name) { return nil, errf("Error: %s is not in the password store.", name) } ref, err := s.vaultRef(name) if err != nil { return nil, err } ct, err := s.readCipher(name) if err != nil { return nil, err } return v.decrypt(ref, ct) } // encryptEntry encrypts content for an entry using its governing Vault key and // writes the `.gpg` file. func encryptEntry(s *store, v *vaultClient, name string, content []byte) error { ref, err := s.vaultRef(name) if err != nil { return err } ct, err := v.encrypt(ref, content) if err != nil { return err } return s.writeCipher(name, ct) } // confirm asks a yes/no question on stderr, defaulting to no. func confirm(prompt string) bool { fmt.Fprintf(os.Stderr, "%s [y/N] ", prompt) line, _ := bufio.NewReader(os.Stdin).ReadString('\n') line = strings.ToLower(strings.TrimSpace(line)) return line == "y" || line == "yes" }