-
Notifications
You must be signed in to change notification settings - Fork 1
/
efi_test.go
48 lines (46 loc) · 1.42 KB
/
efi_test.go
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
package tcglog
import (
"bytes"
"testing"
)
func TestEFIVariableEventDataEncode(t *testing.T) {
for _, data := range []struct {
desc string
in EFIVariableEventData
out []byte
}{
{
desc: "db",
in: EFIVariableEventData{
VariableName: EFIGUID{0xd719b2cb, 0x3d3a, 0x4596, 0xa3bc,
[...]uint8{0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f}},
UnicodeName: "db",
VariableData: []byte("foo")},
out: []byte{0xcb, 0xb2, 0x19, 0xd7, 0x3a, 0x3d, 0x96, 0x45, 0xa3, 0xbc, 0xda, 0xd0, 0x0e,
0x67, 0x65, 0x6f, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x62, 0x00, 0x66, 0x6f, 0x6f},
},
{
desc: "dbx",
in: EFIVariableEventData{
VariableName: EFIGUID{0xd719b2cb, 0x3d3a, 0x4596, 0xa3bc,
[...]uint8{0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f}},
UnicodeName: "dbx",
VariableData: []byte("bar")},
out: []byte{0xcb, 0xb2, 0x19, 0xd7, 0x3a, 0x3d, 0x96, 0x45, 0xa3, 0xbc, 0xda, 0xd0, 0x0e,
0x67, 0x65, 0x6f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x62, 0x00, 0x78, 0x00, 0x62, 0x61,
0x72},
},
} {
t.Run(data.desc, func(t *testing.T) {
var buf bytes.Buffer
if err := data.in.EncodeMeasuredBytes(&buf); err != nil {
t.Fatalf("Encode failed: %v", err)
}
if !bytes.Equal(buf.Bytes(), data.out) {
t.Errorf("Unexpected encoding")
}
})
}
}