//go:build gofuzz package protocol import "bytes" // Fuzz is the OSS-Fuzz entry point for the six protocol objects. It asserts the // injection property of PROTOCOL.md section 12.4: any byte string that decodes // must be exactly the canonical encoding of the object decoded from it, so a // signature cannot be transplanted between two byte strings that denote one // object (encode(decode(b)) == b). The decoder is total: a decode error never // yields a usable object. // // Compiled only under the "gofuzz" build tag (go-fuzz / OSS-Fuzz); the // testing.F-based targets in the package's test files are excluded there. func Fuzz(data []byte) int { interesting := 0 if o, err := DecodeIdentity(data); err == nil { if out, e := EncodeIdentity(o); e == nil && bytes.Equal(out, data) { interesting = 1 } } if o, err := DecodeClaim(data); err == nil { if out, e := EncodeClaim(o); e == nil && bytes.Equal(out, data) { interesting = 1 } } if o, err := DecodeRevocation(data); err == nil { if out, e := EncodeRevocation(o); e == nil && bytes.Equal(out, data) { interesting = 1 } } if o, err := DecodeApprovalRequest(data); err == nil { if out, e := EncodeApprovalRequest(o); e == nil && bytes.Equal(out, data) { interesting = 1 } } if o, err := DecodeApprovalResponse(data); err == nil { if out, e := EncodeApprovalResponse(o); e == nil && bytes.Equal(out, data) { interesting = 1 } } if o, err := DecodeAuthAssertion(data); err == nil { if out, e := EncodeAuthAssertion(o); e == nil && bytes.Equal(out, data) { interesting = 1 } } return interesting }