From eda08ad9b69d037b0dabbbdaef0a8be3ffaa89c3 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sat, 31 May 2025 17:54:12 -0400 Subject: [PATCH] Standardize some variable names; port to latest libmutton development version --- go.mod | 2 +- go.sum | 4 ++-- src/cli/add.go | 10 +++++----- src/cli/edit.go | 26 +++++++++++++------------- src/cli/utilitiesMisc.go | 8 ++++---- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 0f1fda6..57413ba 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/Trojan2021/BEAN v0.0.0-20241210230804-8f294833b514 github.com/charmbracelet/glamour v0.7.0 github.com/rwinkhart/go-boilerplate v0.0.0-20250529185306-e2e64d7fa43b - github.com/rwinkhart/libmutton v0.3.2-0.20250530043633-6e74e37e5bd2 + github.com/rwinkhart/libmutton v0.3.2-0.20250531214811-ca277ba7735d golang.org/x/term v0.32.0 ) diff --git a/go.sum b/go.sum index d3dc46c..a22841d 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,8 @@ github.com/rwinkhart/go-boilerplate v0.0.0-20250529185306-e2e64d7fa43b h1:ENgsUl github.com/rwinkhart/go-boilerplate v0.0.0-20250529185306-e2e64d7fa43b/go.mod h1:cnzIF45I0FCOvE4YIB+26pLCUx2kWyY2llKYZruNaRY= github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410 h1:NhHwFM3Pgm6zRUfFKvi0p5ndjfFbVWsRwmmhyFlG4PE= github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= -github.com/rwinkhart/libmutton v0.3.2-0.20250530043633-6e74e37e5bd2 h1:XXpL+jd2FLh1XoxaDY0ANgWAHKzf2D6tlbkBSyY+jhg= -github.com/rwinkhart/libmutton v0.3.2-0.20250530043633-6e74e37e5bd2/go.mod h1:uIz4AJcXW7ZHvvoPlLNWQofTBIbFa1UJ2JI6O+FSQ60= +github.com/rwinkhart/libmutton v0.3.2-0.20250531214811-ca277ba7735d h1:3CdwTMhr7wNn8qmHyyMsT/jPEAB1ebCd4OX58oHrmtA= +github.com/rwinkhart/libmutton v0.3.2-0.20250531214811-ca277ba7735d/go.mod h1:uIz4AJcXW7ZHvvoPlLNWQofTBIbFa1UJ2JI6O+FSQ60= github.com/rwinkhart/peercred-mini v0.1.0 h1:TiS6u8cEWzW55S9X4iVpU72Iuy/NG6rMUJMtUEVEFLw= github.com/rwinkhart/peercred-mini v0.1.0/go.mod h1:+x4Mxc2veE+YePSOpcUasjimh7n799c1KraLuQwHR20= github.com/rwinkhart/rcw v0.2.0 h1:/rFgJ+20OSThipKAX5KPwW2xbPpgh1zl49THmEkkPis= diff --git a/src/cli/add.go b/src/cli/add.go index 0769fe8..6f4639b 100644 --- a/src/cli/add.go +++ b/src/cli/add.go @@ -15,7 +15,7 @@ func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) { back.PrintError("Failed to add entry: "+err.Error(), back.ErrorWrite, true) } - var unencryptedEntry []string + var decryptedEntry []string if entryType < 2 { username := front.Input("Username:") @@ -32,15 +32,15 @@ func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) { url := front.Input("URL:") if front.InputBinary("Add a note to this entry?") { note, _ := editNote([]string{}) - unencryptedEntry = append([]string{password, username, totp, url}, note...) + decryptedEntry = append([]string{password, username, totp, url}, note...) } else { - unencryptedEntry = []string{password, username, totp, url} + decryptedEntry = []string{password, username, totp, url} } } else { note, _ := editNote([]string{}) - unencryptedEntry = append([]string{"", "", "", ""}, note...) + decryptedEntry = append([]string{"", "", "", ""}, note...) } // write and preview the new entry - writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets) + writeEntryCLI(targetLocation, decryptedEntry, hideSecrets) } diff --git a/src/cli/edit.go b/src/cli/edit.go index 7f78401..a3aed74 100644 --- a/src/cli/edit.go +++ b/src/cli/edit.go @@ -28,7 +28,7 @@ func RenameCli(oldLocationIncomplete string) { // EditEntryField edits a field of an entry at targetLocation (user input). func EditEntryField(targetLocation string, hideSecrets bool, field int) { // fetch old entry data (with all required lines present) - unencryptedEntry, err := core.GetOldEntryData(targetLocation, field) + decryptedEntry, err := core.GetOldEntryData(targetLocation, field) if err != nil { back.PrintError("Failed to fetch entry data: "+err.Error(), back.ErrorRead, true) } @@ -36,43 +36,43 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) { // edit the field switch field { case 0: - unencryptedEntry[field] = string(front.InputHidden("Password:")) + decryptedEntry[field] = string(front.InputHidden("Password:")) case 1: - unencryptedEntry[field] = front.Input("Username:") + decryptedEntry[field] = front.Input("Username:") case 2: - unencryptedEntry[field] = string(front.InputHidden("TOTP secret:")) + decryptedEntry[field] = string(front.InputHidden("TOTP secret:")) case 3: - unencryptedEntry[field] = front.Input("URL:") + decryptedEntry[field] = front.Input("URL:") case 4: // edit notes fields // store note and non-note data separately - nonNoteData := unencryptedEntry[:4] - noteData := unencryptedEntry[4:] + fieldsMain := decryptedEntry[:4] + fieldsNote := decryptedEntry[4:] // edit the note - editedNote, noteEdited := editNote(noteData) + editedNote, noteEdited := editNote(fieldsNote) if !noteEdited { // exit early if the note was not edited back.PrintError("Entry is unchanged", 0, true) } - unencryptedEntry = append(nonNoteData, editedNote...) + decryptedEntry = append(fieldsMain, editedNote...) } // write and preview the modified entry - writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets) + writeEntryCLI(targetLocation, decryptedEntry, hideSecrets) } // GenUpdate generates a new password for an entry at targetLocation (user input). func GenUpdate(targetLocation string, hideSecrets bool) { // fetch old entry data - unencryptedEntry, err := core.GetOldEntryData(targetLocation, 0) + decryptedEntry, err := core.GetOldEntryData(targetLocation, 0) if err != nil { back.PrintError("Failed to fetch entry data: "+err.Error(), back.ErrorRead, true) } // generate a new password - unencryptedEntry[0] = inputPasswordGen() + decryptedEntry[0] = inputPasswordGen() // write and preview the modified entry - writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets) + writeEntryCLI(targetLocation, decryptedEntry, hideSecrets) } // editNote uses the user-specified text editor to edit an existing note (or create a new one if baseNote is empty). diff --git a/src/cli/utilitiesMisc.go b/src/cli/utilitiesMisc.go index 2a71b4a..5e29a55 100644 --- a/src/cli/utilitiesMisc.go +++ b/src/cli/utilitiesMisc.go @@ -28,16 +28,16 @@ func inputPasswordGen() string { } // writeEntryCLI writes an entry to targetLocation and previews it (errors if no data is supplied). -func writeEntryCLI(targetLocation string, unencryptedEntry []string, hideSecrets bool) { - if core.EntryIsNotEmpty(unencryptedEntry) { +func writeEntryCLI(targetLocation string, decryptedEntry []string, hideSecrets bool) { + if core.EntryIsNotEmpty(decryptedEntry) { // write the entry to the target location - err := core.WriteEntry(targetLocation, []byte(strings.Join(unencryptedEntry, "\n"))) + err := core.WriteEntry(targetLocation, []byte(strings.Join(decryptedEntry, "\n"))) if err != nil { back.PrintError("Failed to write entry: "+err.Error(), back.ErrorWrite, true) } // preview the entry fmt.Println(back.AnsiBold + "\nEntry Preview:" + back.AnsiReset) - EntryReader(unencryptedEntry, hideSecrets, true) + EntryReader(decryptedEntry, hideSecrets, true) } else { back.PrintError("No data supplied for entry", back.ErrorTargetNotFound, true) }