age

Simple, secure encryption with UNIX-style composability.
git clone git://git.sgregoratto.me/age
Log | Files | Refs | README | LICENSE

format_gofuzz.go (588B)


      1 // +build gofuzz
      2 
      3 package format
      4 
      5 import (
      6 	"bytes"
      7 	"fmt"
      8 	"io"
      9 	"os"
     10 )
     11 
     12 func Fuzz(data []byte) int {
     13 	h, payload, err := Parse(bytes.NewReader(data))
     14 	if err != nil {
     15 		if h != nil {
     16 			panic("h != nil on error")
     17 		}
     18 		if payload != nil {
     19 			panic("payload != nil on error")
     20 		}
     21 		return 0
     22 	}
     23 	w := &bytes.Buffer{}
     24 	if err := h.Marshal(w); err != nil {
     25 		panic(err)
     26 	}
     27 	if _, err := io.Copy(w, payload); err != nil {
     28 		panic(err)
     29 	}
     30 	if !bytes.Equal(w.Bytes(), data) {
     31 		fmt.Fprintf(os.Stderr, "%s\n%q\n%q\n\n", w, data, w)
     32 		panic("Marshal output different from input")
     33 	}
     34 	return 1
     35 }