File: simulator_test.go

package info (click to toggle)
golang-github-smallstep-crypto 0.63.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 3,800 kB
  • sloc: sh: 66; makefile: 50
file content (32 lines) | stat: -rw-r--r-- 517 bytes parent folder | download | duplicates (3)
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
//go:build tpmsimulator

package tss2

import (
	"crypto/rand"
	"encoding/hex"
	"io"
	"testing"

	"github.com/stretchr/testify/require"
	"go.step.sm/crypto/tpm/simulator"
)

var seed string

func init() {
	b := make([]byte, 8)
	if _, err := io.ReadFull(rand.Reader, b); err != nil {
		panic(err)
	}
	seed = hex.EncodeToString(b)
}

func openTPM(t *testing.T) io.ReadWriteCloser {
	t.Helper()

	sim, err := simulator.New(simulator.WithSeed(seed))
	require.NoError(t, err)
	require.NoError(t, sim.Open())
	return sim
}