diff --git a/tpm.go b/tpm.go index 4b954d5..fcec1e9 100644 --- a/tpm.go +++ b/tpm.go @@ -392,11 +392,16 @@ func (t *TPMContext) SetCommandTimeout(timeout time.Duration) error { return ErrTimeoutNotSupported } -// Transport returns the underlying transmission channel for this context. +// Transport returns the underlying transport for this context. func (t *TPMContext) Transport() Transport { return t.transport } +// Device returns the device that the transport for this context was created from. +func (t *TPMContext) Device() TPMDevice { + return t.device +} + // InitProperties executes one or more TPM2_GetCapability commands to initialize properties used // internally by TPMContext. This is normally done automatically by functions that require these // properties when they are used for the first time, but this function is provided so that the @@ -470,7 +475,12 @@ type dummyTPMDevice struct { } func (d *dummyTPMDevice) Open() (Transport, error) { - return d.transport, nil + transport := d.transport + if transport == nil { + return nil, errors.New("cannot open transport from dummy device") + } + d.transport = nil + return transport, nil } func (d *dummyTPMDevice) String() string {