lib: Add file name compression
Allows to compress short arbitrary strings and returns a string using base64 url encoding. Generator for tables included and a few samples has been added. Add more to init.go Tested with fuzzing for crash resistance and symmetry, see fuzz.go
This commit is contained in:
parent
770a6f2cad
commit
cb7534dcdf
8 changed files with 363 additions and 4 deletions
33
lib/encoder/filename/fuzz.go
Normal file
33
lib/encoder/filename/fuzz.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
//+build gofuzz
|
||||
|
||||
package filename
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Run like:
|
||||
// go-fuzz-build -o=fuzz-build.zip -func=Fuzz . && go-fuzz -minimize=5s -bin=fuzz-build.zip -workdir=testdata/corpus -procs=24
|
||||
|
||||
// Fuzz test the provided input.
|
||||
func Fuzz(data []byte) int {
|
||||
// First try to decode as is.
|
||||
// We don't care about the result, it just shouldn't crash.
|
||||
Decode(string(data))
|
||||
|
||||
// Now encode
|
||||
enc := Encode(string(data))
|
||||
|
||||
// And decoded must match
|
||||
decoded, err := Decode(enc)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("error decoding %q, input %q: %v", enc, string(data), err))
|
||||
}
|
||||
if !bytes.Equal(data, []byte(decoded)) {
|
||||
panic(fmt.Sprintf("decode mismatch, encoded: %q, org: %q, got: %q", enc, string(data), decoded))
|
||||
}
|
||||
|
||||
// Everything is good.
|
||||
return 1
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue