...
1 package crypto11
2
3 import (
4 "testing"
5 )
6
7 func TestULongMasking(t *testing.T) {
8 ulongData := uint(0x33221100ddccbbaa)
9 ulongSlice := ulongToBytes(ulongData)
10
11
12 extraLongSlice := append(ulongSlice, ulongSlice...)
13
14 tests := []struct {
15 slice []uint8
16 expected uint
17 }{
18 {ulongSlice[0:0], 0},
19 {ulongSlice[0:1], 0xaa},
20 {ulongSlice[0:2], 0xbbaa},
21 {ulongSlice[0:3], 0xccbbaa},
22 {ulongSlice[0:4], 0xddccbbaa},
23 {ulongSlice[0:5], 0x00ddccbbaa},
24 {ulongSlice[0:6], 0x1100ddccbbaa},
25 {ulongSlice[0:7], 0x221100ddccbbaa},
26 {ulongSlice[0:8], 0x33221100ddccbbaa},
27 {extraLongSlice, 0x33221100ddccbbaa},
28 }
29
30 for _, test := range tests {
31 got := bytesToUlong(test.slice)
32 if test.expected != got {
33 t.Errorf("conversion failed: 0x%X != 0x%X", test.expected, got)
34 }
35 }
36 }
37
View as plain text