Debian Codegraph @

tpm2/transport/test/helper.go

raw symbols SCIP
1 // Package testhelper provides some helper code for TPM transport tests.
2 package testhelperscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2/transport/test`/
3
4 import (
5 "bytesscip-go gomod github.com/golang/go/src go1.22 bytes/"
6 "encoding/binaryscip-go gomod github.com/golang/go/src go1.22 `encoding/binary`/"
7 "errorsscip-go gomod github.com/golang/go/src go1.22 errors/"
8 "testingscip-go gomod github.com/golang/go/src go1.22 testing/"
9
10 "github.com/google/go-tpm/tpm2scip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/"
11 "github.com/google/go-tpm/tpm2/transportscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2/transport`/"
12 )
13
14 // RunTest checks that the connection to the given TPM seems to be working.
15 func RunTestscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2/transport/test`/RunTest().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#, skipErrs []error, tpmOpener func() (transportscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2/transport`/.TPMCloserscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2/transport`/TPMCloser#, error)) {
16 tpm, err := tpmOpener()
17 for _, skipErr := range skipErrs {
18 if errorsscip-go gomod github.com/golang/go/src go1.22 errors/.Isscip-go gomod github.com/golang/go/src go1.22 errors/Is().(err, skipErr) {
19 t.Skipfscip-go gomod github.com/golang/go/src go1.22 testing/common#Skipf().("%v", err)
20 }
21 }
22 if err != nil {
23 t.Fatalfscip-go gomod github.com/golang/go/src go1.22 testing/common#Fatalf().("Failed to open TPM: %v", err)
24 }
25 defer func(tpm transportscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2/transport`/.TPMCloserscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2/transport`/TPMCloser#) {
26 if err := tpm.Closescip-go gomod github.com/golang/go/src go1.22 io/Closer#Close().(); err != nil {
27 t.Fatalfscip-go gomod github.com/golang/go/src go1.22 testing/common#Fatalf().("tpm.Close() = %v", err)
28 }
29 }(tpm)
30
31 // Ping the TPM to ask it what the manufacturer is, as a basic consistency check.
32 cap, err := tpm2scip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/.GetCapabilityscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/GetCapability#{
33 Capabilityscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/GetCapability#Capability.: tpm2scip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/.TPMCapTPMPropertiesscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/TPMCapTPMProperties.,
34 Propertyscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/GetCapability#Property.: uint32(tpm2scip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/.TPMPTManufacturerscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/TPMPTManufacturer.),
35 PropertyCountscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/GetCapability#PropertyCount.: 1,
36 }.Executescip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/GetCapability#Execute().(tpm)
37
38 // We might run into one of the known "skip if this error" cases.
39 for _, skipErr := range skipErrs {
40 if errorsscip-go gomod github.com/golang/go/src go1.22 errors/.Isscip-go gomod github.com/golang/go/src go1.22 errors/Is().(err, skipErr) {
41 t.Skipfscip-go gomod github.com/golang/go/src go1.22 testing/common#Skipf().("%v", err)
42 }
43 }
44 if err != nil {
45 t.Fatalfscip-go gomod github.com/golang/go/src go1.22 testing/common#Fatalf().("GetCapability() = %v", err)
46 }
47 props, err := cap.CapabilityDatascip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/GetCapabilityResponse#CapabilityData..Datascip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/TPMSCapabilityData#Data..TPMPropertiesscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/TPMUCapabilities#TPMProperties().()
48 if err != nil {
49 t.Fatalfscip-go gomod github.com/golang/go/src go1.22 testing/common#Fatalf().("cap.TPMProperties() = %v", err)
50 }
51 if len(props.TPMPropertyscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/TPMLTaggedTPMProperty#TPMProperty.) != 1 {
52 t.Fatalfscip-go gomod github.com/golang/go/src go1.22 testing/common#Fatalf().("GetCapability() = %v properties, want 1", len(props.TPMPropertyscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/TPMLTaggedTPMProperty#TPMProperty.))
53 }
54
55 var idBuf bytesscip-go gomod github.com/golang/go/src go1.22 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#
56 idBuf.Growscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#Grow().(4)
57 binaryscip-go gomod github.com/golang/go/src go1.22 `encoding/binary`/.Writescip-go gomod github.com/golang/go/src go1.22 `encoding/binary`/Write().(&idBuf, binaryscip-go gomod github.com/golang/go/src go1.22 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.22 `encoding/binary`/BigEndian., props.TPMPropertyscip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/TPMLTaggedTPMProperty#TPMProperty.[0].Valuescip-go gomod github.com/google/go-tpm . `github.com/google/go-tpm/tpm2`/TPMSTaggedProperty#Value.)
58 t.Logfscip-go gomod github.com/golang/go/src go1.22 testing/common#Logf().("Manufacturer ID: %q", idBuf.Stringscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#String().())
59 }