| 1 |
// Package simulator provides access to a local simulator for TPM testing. |
| 2 |
package simulator |
| 3 |
|
| 4 |
import ( |
| 5 |
"io" |
| 6 |
|
| 7 |
"github.com/google/go-tpm-tools/simulator" |
| 8 |
"github.com/google/go-tpm/tpm2/transport" |
| 9 |
"github.com/google/go-tpm/tpmutil" |
| 10 |
) |
| 11 |
|
| 12 |
// TPM represents a connection to a TPM simulator. |
| 13 |
type TPM struct { |
| 14 |
transport io.ReadWriteCloser |
| 15 |
} |
| 16 |
|
| 17 |
// Send implements the TPM interface. |
| 18 |
func (t *TPM) Send(input []byte) ([]byte, error) { |
| 19 |
return tpmutil.RunCommandRaw(t.transport, input) |
| 20 |
} |
| 21 |
|
| 22 |
// OpenSimulator starts and opens a TPM simulator. |
| 23 |
func OpenSimulator() (transport.TPMCloser, error) { |
| 24 |
sim, err := simulator.Get() |
| 25 |
if err != nil { |
| 26 |
return nil, err |
| 27 |
} |
| 28 |
return &TPM{ |
| 29 |
transport: sim, |
| 30 |
}, nil |
| 31 |
} |
| 32 |
|
| 33 |
// Close implements the TPM interface. |
| 34 |
func (t *TPM) Close() error { |
| 35 |
return t.transport.Close() |
| 36 |
} |