-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoding_test.go
More file actions
59 lines (51 loc) · 1.23 KB
/
encoding_test.go
File metadata and controls
59 lines (51 loc) · 1.23 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
package cryptanalysis
import (
"bytes"
"testing"
)
type encoding struct {
encoded string
decoded []byte
}
var b64tests = []encoding{
{"YWRtaW4=", []byte("admin")},
{"cGFzc3dvcmQ=", []byte("password")},
{"AAECAwQF", []byte{0, 1, 2, 3, 4, 5}},
}
var hextests = []encoding{
{"61646d696e", []byte("admin")},
{"70617373776f7264", []byte("password")},
{"000102030405", []byte{0, 1, 2, 3, 4, 5}},
}
func TestDecodeB64Str(t *testing.T) {
for _, test := range b64tests {
decoded := DecodeB64Str(test.encoded)
if bytes.Compare(decoded, test.decoded) != 0 {
t.Error("Expected", test.decoded, "got", decoded)
}
}
}
func TestEncodeB64Str(t *testing.T) {
for _, test := range b64tests {
encoded := EncodeB64Str(test.decoded)
if encoded != test.encoded {
t.Error("Expected", test.encoded, "got", encoded)
}
}
}
func TestDecodeHexStr(t *testing.T) {
for _, test := range hextests {
decoded := DecodeHexStr(test.encoded)
if bytes.Compare(decoded, test.decoded) != 0 {
t.Error("Expected", test.decoded, "got", decoded)
}
}
}
func TestEncodeHexStr(t *testing.T) {
for _, test := range hextests {
encoded := EncodeHexStr(test.decoded)
if encoded != test.encoded {
t.Error("Expected", test.encoded, "got", encoded)
}
}
}