Skip to content

Commit

Permalink
Merge 903544e into e204c2e
Browse files Browse the repository at this point in the history
  • Loading branch information
neilpa committed Jun 30, 2018
2 parents e204c2e + 903544e commit fd5b6ad
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ssdeep.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ type Reader interface {
io.Reader
}

var (
// ErrFileTooSmall is returned when a file contains too few bytes.
ErrFileTooSmall = errors.New("did not process files large enough to produce meaningful results")

// ErrBlockSizeTooSmall is returned when a file can't produce a large enough block size.
ErrBlockSizeTooSmall = errors.New("unable to establish a sufficient block size")
)

func (state *ssdeepState) process(r *bufio.Reader) {
state.newRollingState()
b, err := r.ReadByte()
Expand All @@ -127,7 +135,7 @@ func (state *ssdeepState) process(r *bufio.Reader) {
// Returns an error when ssdeep could not be computed on the Reader.
func FuzzyReader(f Reader, size int) (string, error) {
if size < minFileSize {
return "", errors.New("did not process files large enough to produce meaningful results")
return "", ErrFileTooSmall
}
state := newSsdeepState()
state.getBlockSize(size)
Expand All @@ -136,7 +144,7 @@ func FuzzyReader(f Reader, size int) (string, error) {
r := bufio.NewReader(f)
state.process(r)
if state.blockSize < blockMin {
return "", errors.New("unable to establish a sufficient block size")
return "", ErrBlockSizeTooSmall
}
if len(state.hashString1) < spamSumLength/2 {
state.blockSize = state.blockSize / 2
Expand Down

0 comments on commit fd5b6ad

Please sign in to comment.