Skip to content

Commit

Permalink
use types, fix missing cfg error, add wl-copy
Browse files Browse the repository at this point in the history
  • Loading branch information
tjblackheart committed Jun 18, 2023
1 parent ee3e8cb commit a533f21
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
8 changes: 4 additions & 4 deletions cmd/andcli/aegis.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (e aegisEntry) toEntry() *entry {

//

func decryptAEGIS(data, password []byte) ([]entry, error) {
func decryptAEGIS(data, password []byte) (entries, error) {

var vault aegisVault
if err := json.Unmarshal(data, &vault); err != nil {
Expand All @@ -79,12 +79,12 @@ func decryptAEGIS(data, password []byte) ([]entry, error) {
return nil, err
}

var entries []entry
var list entries
for _, e := range db.Entries {
entries = append(entries, *e.toEntry())
list = append(list, *e.toEntry())
}

return entries, nil
return list, nil
}

func deriveAegisMasterKey(v *aegisVault, password []byte) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/andcli/andcli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestDecrypt(t *testing.T) {
return
}
assert.NoError(t, err)
assert.IsType(t, []entry{}, e)
assert.IsType(t, entries{}, e)
})
}
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/andcli/andotp.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (e andotpEntry) toEntry() *entry {

//

func decryptANDOTP(data, password []byte) ([]entry, error) {
func decryptANDOTP(data, password []byte) (entries, error) {
b, err := andotp.Decrypt(data, string(password))
if err != nil {
return nil, err
Expand All @@ -47,10 +47,10 @@ func decryptANDOTP(data, password []byte) ([]entry, error) {
return nil, err
}

var entries []entry
var list entries
for _, e := range ae {
entries = append(entries, *e.toEntry())
list = append(list, *e.toEntry())
}

return entries, nil
return list, nil
}
3 changes: 2 additions & 1 deletion cmd/andcli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ func newConfig(vaultFile, vaultType string) (*config, error) {
if err := os.MkdirAll(cfgDir, 0755); err != nil {
return nil, err
}
} else {
return nil, err
}
return nil, err
}

if _, err = os.Stat(cfgFile); err != nil {
Expand Down
18 changes: 10 additions & 8 deletions cmd/andcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
white = color.New(color.FgWhite, color.Bold)
muted = color.New(color.FgHiWhite, color.Faint)

// ui
// global ui stuff
copyCmd = ""
current = "" // holds an unformatted copy of the current token
copied = false
Expand Down Expand Up @@ -81,38 +81,40 @@ func main() {
os.Exit(0)
}

prefix := danger.Sprint("[ERR]")

cfg, err := newConfig(vaultFile, vaultType)
if err != nil {
log.Fatal("[ERR] ", err)
log.Fatalf("%s: %s\n", prefix, err.Error())
}

if cfg.File == "" {
log.Fatal("[ERR] missing input file, specify one with -f")
log.Fatalf("%s: missing input file, specify one with -f\n", prefix)
}

if cfg.Type == "" {
log.Fatal("[ERR] missing vault type, specify one with -t")
log.Fatalf("%s: missing vault type, specify one with -t\n", prefix)
}

entries, err := decrypt(cfg.File, cfg.Type)
if err != nil {
log.Fatal("[ERR] ", err)
log.Fatalf("%s: %s\n", prefix, err.Error())
}

if err := cfg.save(); err != nil {
log.Fatal("[ERR] ", err)
log.Fatalf("%s: %s\n", prefix, err.Error())
}

output := termenv.DefaultOutput()
output.ClearScreen()

p := tea.NewProgram(newModel(output, cfg.File, entries...))
if _, err := p.Run(); err != nil {
log.Fatal("[ERR] ", err)
log.Fatalf("%s: %s\n", prefix, err.Error())
}
}

func decrypt(vaultFile, vaultType string, p ...[]byte) ([]entry, error) {
func decrypt(vaultFile, vaultType string, p ...[]byte) (entries, error) {
fi, err := os.Stat(vaultFile)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/andcli/tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func newModel(o *termenv.Output, filename string, entries ...entry) *model {
output: o,
}

cmds := []string{"xclip", "pbcopy"} // linux, macos
cmds := []string{"xclip", "wl-copy", "pbcopy"} // xorg, wayland, macos
for _, c := range cmds {
if _, err := exec.LookPath(c); err == nil {
copyCmd = c
Expand Down

0 comments on commit a533f21

Please sign in to comment.