From d5d7180235147c65475bbb7ba340f498b01d35aa Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Sat, 4 Jan 2025 17:05:23 +0000 Subject: [PATCH] Add a Device accessor to TPMContext --- tpm.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 {