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
|
// Package simulator provides access to a local simulator for TPM testing.
package simulator
import (
"io"
"github.com/google/go-tpm-tools/simulator"
"github.com/google/go-tpm/tpm2/transport"
"github.com/google/go-tpm/tpmutil"
)
// TPM represents a connection to a TPM simulator.
type TPM struct {
transport io.ReadWriteCloser
}
// Send implements the TPM interface.
func (t *TPM) Send(input []byte) ([]byte, error) {
return tpmutil.RunCommandRaw(t.transport, input)
}
// OpenSimulator starts and opens a TPM simulator.
func OpenSimulator() (transport.TPMCloser, error) {
sim, err := simulator.Get()
if err != nil {
return nil, err
}
return &TPM{
transport: sim,
}, nil
}
// Close implements the TPM interface.
func (t *TPM) Close() error {
return t.transport.Close()
}
|