-
Notifications
You must be signed in to change notification settings - Fork 0
/
obytes_test.go
108 lines (91 loc) · 2.13 KB
/
obytes_test.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// +build go1.12
package obytes
import (
"crypto/rand"
"testing"
)
// 0x55 0x55
// [0101 0101] [0101 0101]
type iotest struct {
in byte // input
out byte // output
mask_lo byte
mask_hi byte
}
var tests = []iotest{
{byte('A'), 0, 0x55, 0x55},
{byte('A'), 0, 0x05, 0xf5},
{byte('F'), 0, 0xf5, 0x05},
{byte('F'), 0, 0xff, 0x00},
}
func TestObfuscateByte(t *testing.T) {
for i := 0; i < len(tests); i++ {
obfOut, err := obfuscateByte(tests[i].in, tests[i].mask_hi, tests[i].mask_lo)
if err != nil {
t.Logf("ObfuscateByte error\n")
t.Fail()
}
//t.Logf("ObfuscateByte in: %x out: %x\n", tests[i].in, obfOut)
outIn, err := deobfuscateByte(obfOut, tests[i].mask_hi, tests[i].mask_lo)
if err != nil {
t.Logf("DeObfuscateByte error\n")
t.Fail()
}
//t.Logf("DeObfuscateByte in: %x out: %x\n", obfOut, outIn)
if tests[i].in != outIn {
t.Logf("matching error %02x vs %02x\n", tests[i].in, outIn)
t.Fail()
}
}
for i := 0; i < 100000; i++ {
obfIn := make([]byte, 1)
rand.Read(obfIn)
obfOut, err := obfuscateByte(obfIn[0], 0x55, 0x55)
if err != nil {
t.Logf("ObfuscateByte error\n")
t.Fail()
}
outIn, err := deobfuscateByte(obfOut, 0x55, 0x55)
if err != nil {
t.Logf("DeObfuscateByte error\n")
t.Fail()
}
if obfIn[0] != outIn {
t.Logf("matching error %02x vs %02x\n", obfIn[0], outIn)
t.Fail()
}
}
}
func TestObfuscateError(t *testing.T) {
/*
obfOut, err := obfuscateByte(0, 0x55, 0x55)
if err == nil || obfOut != nil {
t.Logf("ObfuscateByte Error Test\n")
t.Fail()
}
*/
obfOut, err := Obfuscate(nil)
if err == nil || obfOut != nil {
t.Logf("Obfuscate Error Test\n")
t.Fail()
}
}
func TestDeObfuscateError(t *testing.T) {
/*
obfOut, err := deobfuscateByte(nil, 0x55, 0x55)
if err == nil || obfOut != 0 {
t.Logf("DeobfuscateByte Error Test\n")
t.Fail()
}
obfOut, err = deobfuscateByte([]byte("123"), 0x55, 0x55)
if err == nil || obfOut != 0 {
t.Logf("DeobfuscateByte Error Test\n")
t.Fail()
}
*/
obfOutByte, err := Deobfuscate(nil)
if err == nil || obfOutByte != nil {
t.Logf("Deobfuscate Error Test\n")
t.Fail()
}
}