MCPcopy Index your code
hub / github.com/gobwas/ws / TestCipher

Function TestCipher

cipher_test.go:10–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestCipher(t *testing.T) {
11 type test struct {
12 name string
13 in []byte
14 mask [4]byte
15 offset int
16 }
17 cases := []test{
18 {
19 name: "simple",
20 in: []byte("Hello, XOR!"),
21 mask: [4]byte{1, 2, 3, 4},
22 },
23 {
24 name: "simple",
25 in: []byte("Hello, XOR!"),
26 mask: [4]byte{255, 255, 255, 255},
27 },
28 }
29 for offset := 0; offset < 4; offset++ {
30 for tail := 0; tail < 8; tail++ {
31 for b64 := 0; b64 < 3; b64++ {
32 var (
33 ln = remain[offset]
34 rn = tail
35 n = b64*8 + ln + rn
36 )
37
38 p := make([]byte, n)
39 rand.Read(p)
40
41 var m [4]byte
42 rand.Read(m[:])
43
44 cases = append(cases, test{
45 in: p,
46 mask: m,
47 offset: offset,
48 })
49 }
50 }
51 }
52 for _, test := range cases {
53 t.Run(test.name, func(t *testing.T) {
54 // naive implementation of xor-cipher
55 exp := cipherNaive(test.in, test.mask, test.offset)
56
57 res := make([]byte, len(test.in))
58 copy(res, test.in)
59 Cipher(res, test.mask, test.offset)
60
61 if !reflect.DeepEqual(res, exp) {
62 t.Errorf("Cipher(%v, %v):\nact:\t%v\nexp:\t%v\n", test.in, test.mask, res, exp)
63 }
64 })
65 }
66}
67

Callers

nothing calls this directly

Calls 3

cipherNaiveFunction · 0.85
CipherFunction · 0.85
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…