if the seed is random and the build fails, print the seed (#213)

Fixes #212
pull/220/head
Andrew LeFevre 3 years ago committed by GitHub
parent 91deb1e224
commit e014f480f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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))
}
}

@ -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

Loading…
Cancel
Save