diff options
author | Bryan McNulty <bryanmcnulty@protonmail.com> | 2025-04-17 14:19:46 -0500 |
---|---|---|
committer | Bryan McNulty <bryanmcnulty@protonmail.com> | 2025-04-17 14:19:46 -0500 |
commit | 4310ece7b67fe43944f143ad73bab82aa3662ce2 (patch) | |
tree | 7cdc3710a03faea9725970703c72a0c9fd1038d9 /internal | |
parent | c3c2dda30081cda7b0cab820b2e3e15e3c895b77 (diff) | |
download | goexec-4310ece7b67fe43944f143ad73bab82aa3662ce2.tar.gz goexec-4310ece7b67fe43944f143ad73bab82aa3662ce2.zip |
More logging options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/util/util.go | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/internal/util/util.go b/internal/util/util.go index 555297a..d88ec28 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -1,55 +1,41 @@ package util import ( - "github.com/google/uuid" - "math/rand" // not crypto secure - "regexp" - "strings" + "github.com/google/uuid" + "math/rand" // not crypto secure + "regexp" + "strings" ) const randHostnameCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-" const randStringCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" var ( - // Up to 15 characters; only letters, digits, and hyphens (with hyphens not at the start or end). - randHostnameRegex = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9-]{0,14}[a-zA-Z0-9]$`) + // Up to 15 characters; only letters, digits, and hyphens (with hyphens not at the start or end). + randHostnameRegex = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9-]{0,14}[a-zA-Z0-9]$`) ) func RandomHostname() (hostname string) { - for { - // between 2 and 10 characters - if hostname = RandomStringFromCharset(randHostnameCharset, rand.Intn(8)+2); randHostnameRegex.MatchString(hostname) { - return - } - } + for { + // between 2 and 10 characters + if hostname = RandomStringFromCharset(randHostnameCharset, rand.Intn(8)+2); randHostnameRegex.MatchString(hostname) { + return + } + } } func RandomWindowsTempFile() string { - return `\Windows\Temp\` + strings.ToUpper(uuid.New().String()) + return `\Windows\Temp\` + strings.ToUpper(uuid.New().String()) } func RandomString() string { - return RandomStringFromCharset(randStringCharset, rand.Intn(10)+6) + return RandomStringFromCharset(randStringCharset, rand.Intn(10)+6) } func RandomStringFromCharset(charset string, length int) string { - b := make([]byte, length) - for i := range length { - b[i] = charset[rand.Intn(len(charset))] - } - return string(b) -} - -func RandomStringIfBlank(s string) string { - if s == "" { - return RandomString() - } - return s -} - -func CheckNullString(s string) string { - if !strings.HasSuffix(s, "\x00") { - return s + "\x00" - } - return s + b := make([]byte, length) + for i := range length { + b[i] = charset[rand.Intn(len(charset))] + } + return string(b) } |