forked from google/go-tpm-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
open.go
32 lines (27 loc) · 718 Bytes
/
open.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package cmd
import (
"fmt"
"io"
)
// ExternalTPM can be set to run tests against an TPM initialized by an
// external package (like the simulator). Setting this value will make all
// gotpm commands run against it, and will prevent the cmd package from
// closing the TPM. Setting this value and closing the TPM must be managed
// by the external package.
var ExternalTPM io.ReadWriter
type ignoreClose struct {
io.ReadWriter
}
func (ic ignoreClose) Close() error {
return nil
}
func openTpm() (io.ReadWriteCloser, error) {
if ExternalTPM != nil {
return ignoreClose{ExternalTPM}, nil
}
rwc, err := openImpl()
if err != nil {
return nil, fmt.Errorf("connecting to TPM: %w", err)
}
return rwc, nil
}