-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_test.go
80 lines (58 loc) · 1.69 KB
/
convert_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package tpm2genkey
import (
"os"
"testing"
"github.com/google/go-tpm/tpm2"
"github.com/stretchr/testify/require"
)
var ()
func TestToPEMNoAuth(t *testing.T) {
pu, err := os.ReadFile("./testdata/convert/nouserauth/key.pub")
require.NoError(t, err)
pr, err := os.ReadFile("./testdata/convert/nouserauth/key.prv")
require.NoError(t, err)
pemBytes, err := os.ReadFile("./testdata/convert/nouserauth/private.pem")
require.NoError(t, err)
p, err := ToPEM(&ToPEMConfig{
Public: pu,
Private: pr,
Parent: tpm2.TPMRHOwner.HandleValue(),
Password: []byte(""),
Description: "",
Debug: false,
})
require.NoError(t, err)
require.Equal(t, pemBytes, p)
}
func TestToPEMAuth(t *testing.T) {
pu, err := os.ReadFile("./testdata/convert/userauth/key.pub")
require.NoError(t, err)
pr, err := os.ReadFile("./testdata/convert/userauth/key.prv")
require.NoError(t, err)
pemBytes, err := os.ReadFile("./testdata/convert/userauth/private.pem")
require.NoError(t, err)
p, err := ToPEM(&ToPEMConfig{
Public: pu,
Private: pr,
Parent: tpm2.TPMRHOwner.HandleValue(),
Password: []byte("foo"),
Description: "",
Debug: false,
})
require.NoError(t, err)
require.Equal(t, pemBytes, p)
}
func TestFromPEM(t *testing.T) {
pub, err := os.ReadFile("./testdata/convert/nouserauth/key.pub")
require.NoError(t, err)
prb, err := os.ReadFile("./testdata/convert/nouserauth/key.prv")
require.NoError(t, err)
pemBytes, err := os.ReadFile("./testdata/convert/nouserauth/private.pem")
require.NoError(t, err)
_, pu, pr, err := FromPEM(&FromPEMConfig{
PEM: pemBytes,
})
require.NoError(t, err)
require.Equal(t, pu, pub)
require.Equal(t, pr, prb)
}