-
Notifications
You must be signed in to change notification settings - Fork 9
/
nv_test.go
58 lines (45 loc) · 1.31 KB
/
nv_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
49
50
51
52
53
54
55
56
57
58
package tpmk
import (
"testing"
"github.com/google/go-tpm-tools/simulator"
"github.com/google/go-tpm/legacy/tpm2"
"github.com/google/go-tpm/tpmutil"
"github.com/stretchr/testify/require"
)
func TestNVWriteRead(t *testing.T) {
dev, err := simulator.Get()
require.NoError(t, err)
defer dev.Close()
const (
index tpmutil.Handle = 0x1000000
pw = ""
attr = tpm2.AttrOwnerWrite | tpm2.AttrOwnerRead | tpm2.AttrAuthRead | tpm2.AttrPPRead
)
data := append([]byte("testdata"), make([]byte, 1024)...)
err = NVWrite(dev, index, data, pw, attr)
require.NoError(t, err)
out, err := NVRead(dev, index, pw)
require.NoError(t, err)
require.Exactly(t, data, out)
}
func TestNVDelete(t *testing.T) {
dev, err := simulator.Get()
require.NoError(t, err)
defer dev.Close()
const (
index tpmutil.Handle = 0x1000000
pw = ""
attr = tpm2.AttrOwnerWrite | tpm2.AttrOwnerRead | tpm2.AttrAuthRead | tpm2.AttrPPRead
)
data := []byte("testdata")
err = NVWrite(dev, index, data, pw, attr)
require.NoError(t, err)
indexes, err := NVList(dev)
require.NoError(t, err)
require.Contains(t, indexes, index)
err = NVDelete(dev, index, pw)
require.NoError(t, err)
indexes, err = NVList(dev)
require.NoError(t, err)
require.NotContains(t, indexes, index)
}