forked from dvyukov/go-fuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (39 loc) · 866 Bytes
/
main.go
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
// Copyright 2015 Dmitry Vyukov. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package idna
import (
"fmt"
"golang.org/x/net/idna"
)
func Fuzz(data []byte) int {
for _, v := range data {
if v <= 0x20 || v >= 0x80 {
return 0
}
}
dec, err := idna.ToUnicode(string(data))
if err != nil {
return 0
}
enc, err := idna.ToASCII(dec)
if err != nil {
fmt.Printf("data: %q\n", data)
fmt.Printf("dec : %q\n", dec)
panic(err)
}
dec1, err := idna.ToUnicode(enc)
if err != nil {
fmt.Printf("data: %q\n", data)
fmt.Printf("dec : %q\n", dec)
fmt.Printf("enc : %q\n", enc)
panic(err)
}
if dec != dec1 {
fmt.Printf("data: %q\n", data)
fmt.Printf("dec : %q\n", dec)
fmt.Printf("enc : %q\n", enc)
fmt.Printf("dec1: %q\n", dec1)
panic("not equal")
}
return 1
}