Debian Codegraph @

padding/pkcs7_test.go

raw symbols SCIP
1 package padding
2
3 import (
4 "testing"
5 . "gopkg.in/check.v1"
6 )
7
8 func Test(t *testing.T) { TestingT(t) }
9 type TestSuite struct{}
10 var _ = Suite(&TestSuite{})
11
12 func (s *TestSuite) TestRemovePkcs7NoPadding(c *C) {
13 //given
14 padded:=[]byte{1,2,3,4,5,6,7,8}
15
16 //when
17 test:=RemovePkcs7(padded,8)
18
19 //then
20 c.Assert(test, DeepEquals, []byte{1,2,3,4,5,6,7,8})
21 }
22
23 func (s *TestSuite) TestRemovePkcs7(c *C) {
24 //given
25 padded:=[]byte{1,2,3,4,5,3,3,3}
26
27 //when
28 test:=RemovePkcs7(padded,8)
29
30 //then
31 c.Assert(test, DeepEquals, []byte{1,2,3,4,5})
32 }
33
34 func (s *TestSuite) TestRemovePkcs7OneBytePadding(c *C) {
35 //given
36 padded:=[]byte{1,2,3,4,5,1}
37
38 //when
39 test:=RemovePkcs7(padded,6)
40
41 //then
42 c.Assert(test, DeepEquals, []byte{1,2,3,4,5})
43 }
44
45 func (s *TestSuite) TestRemovePkcs7TrailingZeroByte(c *C) {
46 //given
47 padded:=[]byte{1,2,3,4,5,0}
48
49 //when
50 test:=RemovePkcs7(padded,6)
51
52 //then
53 c.Assert(test, DeepEquals, []byte{1,2,3,4,5,0})
54 }
55
56 func (s *TestSuite) TestRemovePkcs7ExtraBlockPadding(c *C) {
57 //given
58 padded:=[]byte{1,2,3,4,5,5,5,5,5,5}
59
60 //when
61 test:=RemovePkcs7(padded,5)
62
63 //then
64 c.Assert(test, DeepEquals, []byte{1,2,3,4,5})
65 }
66
67 func (s *TestSuite) TestRemovePkcs7TrailingByteGreaterBlockSize(c *C) {
68 //given
69 padded:=[]byte{1,2,3,4,5,10}
70
71 //when
72 test:=RemovePkcs7(padded,6)
73
74 //then
75 c.Assert(test, DeepEquals, []byte{1,2,3,4,5,10})
76 }
77
78 func (s *TestSuite) TestAddPkcs7(c *C) {
79 //given
80 in:=[]byte{1,2,3,4,5}
81
82 //when
83 test := AddPkcs7(in,8)
84
85 //then
86 c.Assert(test, DeepEquals, []byte{1,2,3,4,5,3,3,3})
87 }
88
89 func (s *TestSuite) TestAddPkcs7OneBytePadding(c *C) {
90 //given
91 in:=[]byte{1,2,3,4,5}
92
93 //when
94 test := AddPkcs7(in,6)
95
96 //then
97 c.Assert(test, DeepEquals, []byte{1,2,3,4,5,1})
98 }
99
100 func (s *TestSuite) TestAddPkcs7ExtraBlockPadding(c *C) {
101 //given
102 in:=[]byte{1,2,3,4,5,6,7,8}
103
104 //when
105 test := AddPkcs7(in,8)
106
107 //then
108 c.Assert(test, DeepEquals, []byte{1,2,3,4,5,6,7,8,8,8,8,8,8,8,8,8})
109 }