-
Notifications
You must be signed in to change notification settings - Fork 47
/
ent_key_manifest_record.go
54 lines (42 loc) · 1.68 KB
/
ent_key_manifest_record.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
49
50
51
52
53
54
// Copyright 2017-2021 the LinuxBoot Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fit
import (
"bytes"
"fmt"
"io"
"github.com/linuxboot/fiano/pkg/intel/metadata/manifest/key"
)
// EntryKeyManifestRecord represents a FIT entry of type "Key Manifest Record" (0x0B)
type EntryKeyManifestRecord struct{ EntryBase }
var _ EntryCustomGetDataSegmentSizer = (*EntryKeyManifestRecord)(nil)
func (entry *EntryKeyManifestRecord) CustomGetDataSegmentSize(firmware io.ReadSeeker) (uint64, error) {
return uint64(entry.Headers.Size.Uint32()), nil
}
var _ EntryCustomRecalculateHeaderser = (*EntryKeyManifestRecord)(nil)
// CustomRecalculateHeaders recalculates metadata to be consistent with data.
// For example, it fixes checksum, data size, entry type and so on.
func (entry *EntryKeyManifestRecord) CustomRecalculateHeaders() error {
mostCommonRecalculateHeadersOfEntry(entry)
entry.Headers.Size.SetUint32(uint32(len(entry.DataSegmentBytes)))
return nil
}
// ParseData creates EntryKeyManifestRecord from EntryKeyManifest
func (entry *EntryKeyManifestRecord) ParseData() (*key.Manifest, error) {
var km key.Manifest
_, err := km.ReadFrom(bytes.NewReader(entry.DataSegmentBytes))
if err != nil {
return nil, fmt.Errorf("failed to parse KeyManifest, err: %v", err)
}
return &km, nil
}
// ParseKeyManifest returns a boot policy manifest if it was able to
// parse one.
func (table Table) ParseKeyManifest(firmware []byte) (*key.Manifest, error) {
hdr := table.First(EntryTypeKeyManifestRecord)
if hdr == nil {
return nil, ErrNotFound{}
}
return hdr.GetEntry(firmware).(*EntryKeyManifestRecord).ParseData()
}