Skip to content

Commit

Permalink
replace TPMDevice.ShouldRetry with TPMDevice.Config
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisccoulson committed Dec 15, 2023
1 parent 9f69e9b commit 1074da7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
8 changes: 5 additions & 3 deletions linux/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ func (d *TPMDevice) Open() (tpm2.TCTI, error) {
return tcti, err
}

// ShouldRetry implements [tpm2.TPMDevice.ShouldRetry].
func (d *TPMDevice) ShouldRetry() bool {
return false
// Config implements [tpm2.TPMDevice.Config].
func (d *TPMDevice) Config() tpm2.TPMDeviceConfig {
return tpm2.TPMDeviceConfig{
TransparentRetry: true,
}
}

// String implements [fmt.Stringer].
Expand Down
6 changes: 3 additions & 3 deletions mssim/mssim.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func (d *Device) Open() (tpm2.TCTI, error) {
return d.openInternal()
}

// ShouldRetry implements [tpm2.TPMDevice.ShouldRetry].
func (d *Device) ShouldRetry() bool {
return true
// Config implements [tpm2.TPMDevice.Config].
func (d *Device) Config() tpm2.TPMDeviceConfig {
return tpm2.TPMDeviceConfig{}
}

// String implements [fmt.Stringer].
Expand Down
23 changes: 15 additions & 8 deletions tpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (t *TPMContext) RunCommand(commandCode CommandCode, cHandles HandleList, cA
return nil, nil, &InvalidResponseError{commandCode, err}
}

if !t.device.ShouldRetry() || try >= t.maxSubmissions {
if t.device.Config().TransparentRetry || try >= t.maxSubmissions {
return nil, nil, err
}
if !(IsTPMWarning(err, WarningYielded, commandCode) || IsTPMWarning(err, WarningTesting, commandCode) || IsTPMWarning(err, WarningRetry, commandCode)) {
Expand Down Expand Up @@ -470,16 +470,21 @@ func (t *TPMContext) initPropertiesIfNeeded() error {
return t.InitProperties()
}

// TPMDeviceConfig corresponds to the configuration for a TPM device.
type TPMDeviceConfig struct {
// TransparentRetry indicates that the TPM device backend resubmits
// commands when the TPM response indicates that a command should
// be retried.
TransparentRetry bool
}

// TPMDevice corresponds a TPM device.
type TPMDevice interface {
// Open opens a communication channel with the TPM device.
Open() (TCTI, error)

// ShouldRetry indicates whether TPMContext should resubmit commands
// when the TPM response indicates that a command should be retried.
// Some backends may have already retried, in which case TPMContext
// should not retry.
ShouldRetry() bool
// Config returns the configuration for the TPM device.
Config() TPMDeviceConfig

fmt.Stringer
}
Expand Down Expand Up @@ -520,8 +525,10 @@ func (d *dummyTPMDevice) Open() (TCTI, error) {
return d.tcti, nil
}

func (d *dummyTPMDevice) ShouldRetry() bool {
return true
func (d *dummyTPMDevice) Config() TPMDeviceConfig {
return TPMDeviceConfig{
TransparentRetry: false,
}
}

func (d *dummyTPMDevice) String() string {
Expand Down

0 comments on commit 1074da7

Please sign in to comment.