-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnv_read.go
More file actions
43 lines (35 loc) · 762 Bytes
/
Copy pathnv_read.go
File metadata and controls
43 lines (35 loc) · 762 Bytes
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
package main
import (
"fmt"
"os"
"github.com/google/go-tpm/tpm2"
"github.com/google/go-tpm/tpmutil"
)
// nvRead reads the value from an NV Index.
func nvRead() error {
err := ensureAllPassed(fNVReadSet, handleFlagName)
if err != nil {
return err
}
t, err := getTPM(*fNVReadTPM)
if err != nil {
return err
}
defer t.Close()
data, err := tpm2.NVReadEx(t, tpmutil.Handle(fNVReadHandle), tpm2.HandleOwner, *fNVReadPassword, 0)
if err != nil {
return fmt.Errorf("failed to read from NV index: %v", err)
}
var f *os.File
if *fNVReadOut != "" {
f, err = os.Create(*fNVReadOut)
if err != nil {
return fmt.Errorf("failed to create output file: %v", err)
}
defer f.Close()
} else {
f = os.Stdout
}
f.Write(data)
return nil
}