Debian Codegraph @

config/configtls/tpm_open_linux.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 //go:build linux
5
6 package configtls // import "go.opentelemetry.io/collector/config/configtls"
7
8 import (
9 "errors"
10 "fmt"
11
12 "github.com/google/go-tpm/tpm2/transport"
13 "github.com/google/go-tpm/tpmutil"
14 )
15
16 // for testing
17 var tpmSimulator transport.TPMCloser
18
19 func openTPM(path string) func() (transport.TPMCloser, error) {
20 return func() (transport.TPMCloser, error) {
21 if path == "" {
22 return nil, errors.New("TPM path is not set")
23 }
24 if path == "simulator" {
25 return tpmSimulator, nil
26 }
27
28 tpm, err := tpmutil.OpenTPM(path)
29 if err != nil {
30 return nil, fmt.Errorf("failed to open TPM (%s): %w", path, err)
31 }
32 return transport.FromReadWriteCloser(tpm), nil
33 }
34 }