From e014f480f99974a2976166fe5252fc41676a598a Mon Sep 17 00:00:00 2001 From: Andrew LeFevre Date: Sat, 23 Jan 2021 13:34:57 -0500 Subject: [PATCH] if the seed is random and the build fails, print the seed (#213) Fixes #212 --- internal/literals/obfuscators.go | 14 ++------------ main.go | 5 ++++- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/internal/literals/obfuscators.go b/internal/literals/obfuscators.go index d9a7906..d7cf286 100644 --- a/internal/literals/obfuscators.go +++ b/internal/literals/obfuscators.go @@ -4,13 +4,11 @@ package literals import ( - cryptrand "crypto/rand" "fmt" "go/ast" "go/token" mathrand "math/rand" "os" - "strings" ) // obfuscator takes a byte slice and converts it to a ast.BlockStmt @@ -35,16 +33,8 @@ var ( // genRandBytes return a random []byte with the length of size. func genRandBytes(buffer []byte) { - if strings.HasPrefix(envGarbleSeed, "random;") { - _, err := cryptrand.Read(buffer) - if err != nil { - panic(fmt.Sprintf("couldn't generate random key: %v", err)) - } - } else { - _, err := mathrand.Read(buffer) - if err != nil { - panic(fmt.Sprintf("couldn't generate random key: %v", err)) - } + if _, err := mathrand.Read(buffer); err != nil { + panic(fmt.Sprintf("couldn't generate random key: %v", err)) } } diff --git a/main.go b/main.go index 4188807..0084769 100644 --- a/main.go +++ b/main.go @@ -170,6 +170,9 @@ func main1() int { case errJustExit: default: fmt.Fprintln(os.Stderr, err) + if flagSeed == "random" { + fmt.Fprintf(os.Stderr, "random seed: %s\n", base64.RawStdEncoding.EncodeToString(opts.Seed)) + } } return 1 } @@ -238,7 +241,7 @@ How to install Go: https://golang.org/doc/install } func mainErr(args []string) error { - // If we recognise an argument, we're not running within -toolexec. + // If we recognize an argument, we're not running within -toolexec. switch cmd := args[0]; cmd { case "help": return flag.ErrHelp