aboutsummaryrefslogtreecommitdiff
path: root/fuzz/gencorpus.go
blob: 368192b1363b42b0a6ef0332ebbe1604eed5813d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main

import (
	"fmt"
	"io"
	"math/rand"
	"os"
	"reflect"
	"testing/quick"

	"github.com/gorilla/securecookie"
)

var hashKey = []byte("very-secret12345")
var blockKey = []byte("a-lot-secret1234")
var s = securecookie.New(hashKey, blockKey)

type Cookie struct {
	B bool
	I int
	S string
}

func main() {
	var c Cookie
	t := reflect.TypeOf(c)
	rnd := rand.New(rand.NewSource(0))
	for i := 0; i < 100; i++ {
		v, ok := quick.Value(t, rnd)
		if !ok {
			panic("couldn't generate value")
		}
		encoded, err := s.Encode("fuzz", v.Interface())
		if err != nil {
			panic(err)
		}
		f, err := os.Create(fmt.Sprintf("corpus/%d.sc", i))
		if err != nil {
			panic(err)
		}
		_, err = io.WriteString(f, encoded)
		if err != nil {
			panic(err)
		}
		f.Close()
	}
}