Skip to content

Commit

Permalink
Add a Device accessor to TPMContext
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisccoulson committed Jan 4, 2025
1 parent dcd2af7 commit d5d7180
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d5d7180

Please sign in to comment.