-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpadding_test.go
More file actions
50 lines (43 loc) · 1.22 KB
/
padding_test.go
File metadata and controls
50 lines (43 loc) · 1.22 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
package insecurecrypto
import (
"bytes"
"testing"
)
func isPaddingConsistent(in []byte, t *testing.T) {
padded, err := AddPadding(in, 16)
if err != nil {
t.Errorf("Got unexpected error: %s", err)
}
padThenUnpad, err := RemovePadding(padded)
if err != nil {
t.Errorf("Got unexpected error: %s", err)
}
if !bytes.Equal(padThenUnpad, in) {
t.Errorf("Failed to unpad!\nexpected:\n%q\ngot:\n%q", in, padThenUnpad)
}
}
func TestPadding(t *testing.T) {
t.Run(
"padding is correct",
func(t *testing.T) {
testString := []byte("I LIKE TO PAD MY MESSAGES")
got, err := pkcs7Padding(testString, 30)
if err != nil {
t.Errorf("Got unexpected error: %s", err)
}
expectString := []byte("I LIKE TO PAD MY MESSAGES\x05\x05\x05\x05\x05")
if !bytes.Equal(got, expectString) {
t.Errorf("Failed to pad!\nexpected:\n%q\ngot:\n%q", expectString, got)
}
},
)
t.Run(
"padding is consistent",
func(t *testing.T) {
isPaddingConsistent([]byte("I LIKE TO PAD MY MESSAGES"), t)
isPaddingConsistent([]byte("a"), t)
isPaddingConsistent([]byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), t)
isPaddingConsistent([]byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), t)
},
)
}