mirror of
https://github.com/google/go-attestation.git
synced 2024-12-18 20:47:57 +00:00
Add InjectSimulatedTPMForTest function for testing (#187)
This commit is contained in:
parent
6bd14729ac
commit
d90962df3c
22
attest/tpm_fake.go
Normal file
22
attest/tpm_fake.go
Normal file
@ -0,0 +1,22 @@
|
||||
package attest
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
var (
|
||||
testLog = []byte{0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x21, 0x0, 0x0, 0x0, 0x53, 0x70, 0x65, 0x63, 0x20, 0x49, 0x44,
|
||||
0x20, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, 0x33, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x2, 0x0, 0x2, 0x1, 0x0, 0x0, 0x0, 0xb, 0x0, 0x20, 0x0, 0x0}
|
||||
)
|
||||
|
||||
type fakeCmdChannel struct {
|
||||
io.ReadWriteCloser
|
||||
}
|
||||
|
||||
// MeasurementLog implements CommandChannelTPM20.
|
||||
func (cc *fakeCmdChannel) MeasurementLog() ([]byte, error) {
|
||||
return testLog, nil
|
||||
}
|
@ -35,6 +35,16 @@ const (
|
||||
// This will be initialized if we build with CGO (needed for TPM 1.2 support).
|
||||
var getTPM12Impl func() (*TPM, error)
|
||||
|
||||
// InjectSimulatedTPMForTest returns a fake TPM that interfaces with
|
||||
// the provided simulated TPM. This method should be used for testing
|
||||
// only.
|
||||
func InjectSimulatedTPMForTest(rwc io.ReadWriteCloser) *TPM {
|
||||
return &TPM{tpm: &wrappedTPM20{
|
||||
interf: TPMInterfaceCommandChannel,
|
||||
rwc: &fakeCmdChannel{rwc},
|
||||
}}
|
||||
}
|
||||
|
||||
func probeSystemTPMs() ([]probedTPM, error) {
|
||||
var tpms []probedTPM
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user