mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-09-20 22:51:55 +00:00
b48ac24c46
* init 4 dedupin * use raw rather than rawv2 * rm comment * comments * nits * clean up and use rawv2 too * add decoder order test
39 lines
878 B
Go
39 lines
878 B
Go
package decoders
|
|
|
|
import (
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
|
|
)
|
|
|
|
func DefaultDecoders() []Decoder {
|
|
return []Decoder{
|
|
// UTF8 must be first for duplicate detection
|
|
&UTF8{},
|
|
&Base64{},
|
|
&UTF16{},
|
|
}
|
|
}
|
|
|
|
type Decoder interface {
|
|
FromChunk(chunk *sources.Chunk) *sources.Chunk
|
|
}
|
|
|
|
// Fuzz is an entrypoint for go-fuzz, which is an AFL-style fuzzing tool.
|
|
// This one attempts to uncover any panics during decoding.
|
|
func Fuzz(data []byte) int {
|
|
decoded := false
|
|
for i, decoder := range DefaultDecoders() {
|
|
// Skip the first decoder (plain), because it will always decode and give
|
|
// priority to the input (return 1).
|
|
if i == 0 {
|
|
continue
|
|
}
|
|
chunk := decoder.FromChunk(&sources.Chunk{Data: data})
|
|
if chunk != nil {
|
|
decoded = true
|
|
}
|
|
}
|
|
if decoded {
|
|
return 1 // prioritize the input
|
|
}
|
|
return -1 // Don't add input to the corpus.
|
|
}
|