-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_fuzz_test.go
More file actions
77 lines (69 loc) · 1.46 KB
/
encode_fuzz_test.go
File metadata and controls
77 lines (69 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-License-Identifier: EUPL-1.2
package core_test
import (
. "dappco.re/go"
)
func FuzzHexDecode(f *F) {
f.Add("deadbeef")
f.Add("DEADBEEF")
f.Add("68656c6c6f")
f.Add("abc")
f.Add("zz")
f.Add("0")
f.Add("f")
f.Add("")
f.Fuzz(func(t *T, raw string) {
r := HexDecode(raw)
if r.OK {
b := r.Value.([]byte)
encoded := HexEncode(b)
roundTrip := HexDecode(Lower(encoded))
if !roundTrip.OK {
t.Errorf("HexDecode produced bytes that HexEncode cannot decode raw=%q encoded=%q", raw, encoded)
}
}
})
}
func FuzzBase64Decode(f *F) {
f.Add("SGVsbG8=")
f.Add("TWE=")
f.Add("TQ==")
f.Add("SGVsbG8")
f.Add("!!!!")
f.Add("A")
f.Add("====")
f.Add("")
f.Fuzz(func(t *T, raw string) {
r := Base64Decode(raw)
if r.OK {
b := r.Value.([]byte)
encoded := Base64Encode(b)
roundTrip := Base64Decode(encoded)
if !roundTrip.OK {
t.Errorf("Base64Decode produced bytes that Base64Encode cannot decode raw=%q encoded=%q", raw, encoded)
}
}
})
}
func FuzzBase64URLDecode(f *F) {
f.Add("aGVsbG8=")
f.Add("TWE=")
f.Add("TQ==")
f.Add("-_8=")
f.Add("YW55LWJ5dGVz")
f.Add("SGVsbG8")
f.Add("!!!!")
f.Add("A")
f.Add("")
f.Fuzz(func(t *T, raw string) {
r := Base64URLDecode(raw)
if r.OK {
b := r.Value.([]byte)
encoded := Base64URLEncode(b)
roundTrip := Base64URLDecode(encoded)
if !roundTrip.OK {
t.Errorf("Base64URLDecode produced bytes that Base64URLEncode cannot decode raw=%q encoded=%q", raw, encoded)
}
}
})
}