-
Notifications
You must be signed in to change notification settings - Fork 0
/
pv.go
45 lines (39 loc) · 905 Bytes
/
pv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/////////////////////////////////////////
// pv.go - Secret password vault termui
// Mike Schilli, 2022 ([email protected])
/////////////////////////////////////////
package main
import (
"bufio"
"errors"
"flag"
"fmt"
"golang.org/x/crypto/ssh/terminal"
"os"
"strings"
)
func main() {
add := flag.Bool("add", false, "Add new password entry")
flag.Parse()
fmt.Printf("Password: ")
password, err := terminal.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
txt, err := readEnc(string(password))
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
panic(err)
}
}
if *add {
fmt.Printf("\rNew entry: ")
reader := bufio.NewReader(os.Stdin)
entry, _ := reader.ReadString('\n')
txt = txt + entry
writeEnc(txt, string(password))
return
}
lines := strings.Split(strings.TrimSuffix(txt, "\n"), "\n")
runUI(lines)
}