From 530fde8f11f12926daac68e35cb0d56cf83ac135 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Thu, 18 Jul 2024 17:04:48 -0400 Subject: [PATCH] Improve StringGen to allow creating file name-safe complex strings; remove in-code references to future additions --- docs/man | 1 - mutn.go | 6 +++--- src/backend/utilitiesMisc.go | 15 +++++++++++---- src/cli/add.go | 5 +++-- src/cli/edit.go | 2 +- src/cli/init.go | 2 +- src/cli/printInfo.go | 1 - src/sync/init.go | 5 +++-- 8 files changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/man b/docs/man index 6d83b12..eaf9573 100644 --- a/docs/man +++ b/docs/man @@ -47,7 +47,6 @@ Manually synchronizing entries with the server: help Bring up the help menu version Display version and license information init Set up MUTN (generates libmutton.ini) - tweak Change configuration options (NOT YET IMPLEMENTED) copy Copy details of an entry to your clipboard edit Edit an existing entry gen Generate a new password diff --git a/mutn.go b/mutn.go index a4447ae..e658f7a 100644 --- a/mutn.go +++ b/mutn.go @@ -2,11 +2,12 @@ package main import ( "fmt" + "os" + "strings" + "github.com/rwinkhart/MUTN/src/backend" "github.com/rwinkhart/MUTN/src/cli" "github.com/rwinkhart/MUTN/src/sync" - "os" - "strings" ) func main() { @@ -165,7 +166,6 @@ func main() { case "tweak": fmt.Println(backend.AnsiError + "\"tweak\" is not yet implemented" + backend.AnsiReset) os.Exit(0) - // TODO backend.Tweak() case "copy": cli.HelpCopy() case "edit": diff --git a/src/backend/utilitiesMisc.go b/src/backend/utilitiesMisc.go index 9359eb6..4fec3f7 100644 --- a/src/backend/utilitiesMisc.go +++ b/src/backend/utilitiesMisc.go @@ -11,8 +11,6 @@ import ( "strings" ) -const extendedCharset = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" - // TargetIsFile TargetStatusCheck checks if the targetLocation is a file, directory, or is inaccessible // failCondition: 0 = fail on inaccessible, 1 = fail on inaccessible/file, 2 = fail on inaccessible/directory // returns: isFile, isAccessible @@ -88,15 +86,24 @@ func RemoveTrailingEmptyStrings(slice []string) []string { } // StringGen generates a random string of a specified length and complexity +// safeForFileName: if true, the generated string will only contain special characters that are safe for file names (only impacts complex strings) // complexity: minimum percentage of special characters to be returned in the generated string (only impacts complex strings) -func StringGen(length int, complex bool, complexity float64) string { +func StringGen(length int, complex bool, complexity float64, safeForFileName bool) string { var actualSpecialChars int // track the number of special characters in the generated string var minSpecialChars int // track the minimum number of special characters to accept + var extendedCharset string // additions to character set used for complex strings charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" // default character set used for all strings + const extendedCharsetFiles = "!#$%&'()+,-.;=@[]^_`{}~" // additional special characters for complex strings (safe in file names) + const extendedCharsetPassword = "\"*:>