Sync with latest libmutton development version

This commit is contained in:
2026-02-13 18:50:02 -05:00
parent d6d9a56532
commit 70ac2ad8ee
9 changed files with 57 additions and 58 deletions
+1 -1
View File
@@ -19,5 +19,5 @@ const (
)
func init() {
global.GetPassword = front.InputHidden
global.GetPassword = front.InputSecret
}
+8 -8
View File
@@ -18,24 +18,24 @@ func AddEntry(realPath string, entryType uint8) {
var decSlice []string
var password string
var password []byte
if entryType < 2 {
username := front.Input("Username:")
// determine whether to generate the password
if entryType == 0 {
password = string(front.InputHidden("Password:"))
password = front.InputSecret("Password:")
} else {
password = inputPasswordGen()
}
totp := string(front.InputHidden("TOTP secret:"))
totp := string(front.InputSecret("TOTP secret:"))
url := front.Input("URL:")
if front.InputBinary("Add a note to this entry?") {
note, _ := editNote([]string{})
decSlice = append([]string{password, username, totp, url}, note...)
decSlice = append([]string{string(password), username, totp, url}, note...)
} else {
decSlice = []string{password, username, totp, url}
decSlice = []string{string(password), username, totp, url}
}
} else {
note, _ := editNote([]string{})
@@ -43,9 +43,9 @@ func AddEntry(realPath string, entryType uint8) {
}
// write and preview the new entry
if password != "" {
writeEntryCLI(realPath, decSlice, true, "")
if password != nil {
writeEntryCLI(realPath, decSlice, true, nil)
} else {
writeEntryCLI(realPath, decSlice, false, "")
writeEntryCLI(realPath, decSlice, false, nil)
}
}
+7 -8
View File
@@ -21,7 +21,7 @@ import (
// fields without having to re-decrypt each time. decSlice can be left nil
// to decrypt the entry specified by vanityPath. If the entry was provided
// decrypted, CopyMenu assumes it was edited and triggers a sync.
func CopyMenu(vanityPath string, decSlice []string, oldPassword string) {
func CopyMenu(vanityPath string, decSlice []string, oldPassword []byte) {
realPath := global.GetRealPath(vanityPath)
var err error
if decSlice == nil {
@@ -45,7 +45,7 @@ func CopyMenu(vanityPath string, decSlice []string, oldPassword string) {
for i := range indices {
if len(decSlice) > indices[i] && decSlice[indices[i]] != "" {
fieldOptions = append(fieldOptions, fieldStrings[i])
if indices[i] == 0 && oldPassword != "" {
if indices[i] == 0 && oldPassword != nil {
fieldOptions = append(fieldOptions, "Old Password")
}
}
@@ -65,7 +65,7 @@ func CopyMenu(vanityPath string, decSlice []string, oldPassword string) {
signal.Notify(sigChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigChan
if err = clip.ClearProcess(""); err != nil {
if err = clip.ClearProcess(nil); err != nil {
other.PrintError("Failed to clear clipboard on exit: "+err.Error(), global.ErrorClipboard)
}
os.Exit(0)
@@ -105,7 +105,7 @@ func CopyMenu(vanityPath string, decSlice []string, oldPassword string) {
}
selectedField = fieldOptions[choice-1]
if selectedField == "Old Password" {
if err = clip.CopyString(false, oldPassword); err != nil {
if err = clip.CopyBytes(false, oldPassword); err != nil {
other.PrintError("Failed to copy old password to clipboard: "+err.Error(), global.ErrorClipboard)
}
continue
@@ -113,14 +113,13 @@ func CopyMenu(vanityPath string, decSlice []string, oldPassword string) {
choice = indices[slices.Index(fieldStrings, selectedField)]
if choice == 2 {
fmt.Println(back.AnsiWarning + "[Starting]" + back.AnsiReset + " TOTP clipboard refresher")
errorChan := make(chan error)
errorChan := make(chan error, 1)
done := make(chan bool)
go clip.TOTPCopier(decSlice[2], errorChan, done)
// block until first successful copy
if err = <-errorChan; err != nil {
other.PrintError("Failed to copy TOTP token: "+err.Error(), global.ErrorClipboard)
}
fmt.Println(back.AnsiGreen + "[Started]" + back.AnsiReset + " TOTP clipboard refresher")
// block until the user sends "q"
for {
input := front.Input("Service will run until 'q' is entered:")
@@ -129,9 +128,9 @@ func CopyMenu(vanityPath string, decSlice []string, oldPassword string) {
}
}
close(done)
fmt.Println(back.AnsiBlue + "\n[Stopped]" + back.AnsiReset + " TOTP clipboard refresher")
fmt.Println(back.AnsiBlue + "[Stopped]" + back.AnsiReset + " TOTP clipboard refresher")
} else {
if err = clip.CopyString(false, decSlice[choice]); err != nil {
if err = clip.CopyBytes(false, []byte(decSlice[choice])); err != nil {
other.PrintError("Failed to copy field to clipboard: "+err.Error(), global.ErrorClipboard)
}
}
+6 -6
View File
@@ -34,15 +34,15 @@ func EditEntryField(realPath string, field int) {
}
// edit the field
var oldPassword string
var oldPassword []byte
switch field {
case 0:
oldPassword = decSlice[field]
decSlice[field] = string(front.InputHidden("Password:"))
oldPassword = []byte(decSlice[field])
decSlice[field] = string(front.InputSecret("Password:"))
case 1:
decSlice[field] = front.Input("Username:")
case 2:
decSlice[field] = string(front.InputHidden("TOTP secret:"))
decSlice[field] = string(front.InputSecret("TOTP secret:"))
case 3:
decSlice[field] = front.Input("URL:")
case 4: // edit notes fields
@@ -75,8 +75,8 @@ func GenUpdate(realPath string) {
}
// generate a new password
oldPassword := decSlice[0]
decSlice[0] = inputPasswordGen()
oldPassword := []byte(decSlice[0])
decSlice[0] = string(inputPasswordGen())
// write and preview the modified entry
writeEntryCLI(realPath, decSlice, true, oldPassword)
+1 -1
View File
@@ -152,7 +152,7 @@ func Version() {
ansiVersionOutline + "<><><><><><><><><><><><><><>-<><><><><><><><><><><><><><>\n" +
"\\" + ansiBlackOnWhite + " " + back.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " MUTN v" + MUTNVersion + " " + back.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " The Cryptic Cuts Update " + back.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " The \"Hardy Herd\" Update " + back.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " " + back.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " Built with libmutton v" + global.LibmuttonVersion + " " + back.AnsiReset + ansiVersionOutline + "/\n" +
"\\" + ansiBlackOnWhite + " " + back.AnsiReset + ansiVersionOutline + "/\n" +
+4 -4
View File
@@ -6,12 +6,12 @@ import (
"github.com/rwinkhart/go-boilerplate/back"
"github.com/rwinkhart/go-boilerplate/front"
"github.com/rwinkhart/go-boilerplate/other"
"github.com/rwinkhart/go-boilerplate/stringy"
"github.com/rwinkhart/go-boilerplate/security"
"github.com/rwinkhart/libmutton/core"
)
// inputPasswordGen prompts the user for password generation parameters and returns a generated password as a string.
func inputPasswordGen() string {
func inputPasswordGen() []byte {
passLength := front.InputInt("Password length:", 1, -1)
fmt.Println()
passCharset := uint8(front.InputMenuGen("Password complexity:", []string{"Simple", "Complex", "Ultra Complex (not compatible with many services)"}))
@@ -24,11 +24,11 @@ func inputPasswordGen() string {
complexity = 0.2 // (ultra) complex
// 2 and 3 indicate complex and ultra complex charsets, respectively
}
return stringy.StringGen(passLength, complexity, passCharset)
return security.BytesGen(passLength, complexity, passCharset)
}
// writeEntryCLI writes decSlice to realPath and previews it (errors if no data is supplied).
func writeEntryCLI(realPath string, decSlice []string, passwordIsNew bool, oldPassword string) {
func writeEntryCLI(realPath string, decSlice []string, passwordIsNew bool, oldPassword []byte) {
if core.EntryIsNotEmpty(decSlice) {
if err := core.WriteEntry(realPath, decSlice, passwordIsNew, nil); err != nil {
other.PrintError("Failed to write entry: "+err.Error(), back.ErrorWrite)