-
Notifications
You must be signed in to change notification settings - Fork 1
/
sdefistub.go
36 lines (28 loc) · 939 Bytes
/
sdefistub.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
package tcglog
import (
"bytes"
"encoding/binary"
"fmt"
"io"
)
type SystemdEFIStubEventData struct {
data []byte
Str string
}
func (e *SystemdEFIStubEventData) String() string {
return fmt.Sprintf("%s", e.Str)
}
func (e *SystemdEFIStubEventData) Bytes() []byte {
return e.data
}
func (e *SystemdEFIStubEventData) EncodeMeasuredBytes(buf io.Writer) error {
return binary.Write(buf, binary.LittleEndian, append(convertStringToUtf16(e.Str), 0))
}
func decodeEventDataSystemdEFIStub(data []byte) (EventData, int, error) {
// data is a UTF-16 string in little-endian form terminated with a single zero byte.
// Omit the zero byte added by the EFI stub and then convert to native byte order.
reader := bytes.NewReader(data[:len(data)-1])
utf16Str := make([]uint16, len(data)/2)
binary.Read(reader, binary.LittleEndian, &utf16Str)
return &SystemdEFIStubEventData{data: data, Str: convertUtf16ToString(utf16Str)}, 0, nil
}