MCPcopy
hub / github.com/grpc/grpc-go / loadKeyMaterials

Function loadKeyMaterials

credentials/tls/certprovider/store_test.go:119–134  ·  view source on GitHub ↗

loadKeyMaterials is a helper to read cert/key files from testdata and convert them into a KeyMaterialReader struct.

(t *testing.T, cert, key, ca string)

Source from the content-addressed store, hash-verified

117// loadKeyMaterials is a helper to read cert/key files from testdata and convert
118// them into a KeyMaterialReader struct.
119func loadKeyMaterials(t *testing.T, cert, key, ca string) *KeyMaterial {
120 t.Helper()
121
122 certs, err := tls.LoadX509KeyPair(testdata.Path(cert), testdata.Path(key))
123 if err != nil {
124 t.Fatalf("Failed to load keyPair: %v", err)
125 }
126
127 pemData, err := os.ReadFile(testdata.Path(ca))
128 if err != nil {
129 t.Fatal(err)
130 }
131 roots := x509.NewCertPool()
132 roots.AppendCertsFromPEM(pemData)
133 return &KeyMaterial{Certs: []tls.Certificate{certs}, Roots: roots}
134}
135
136// kmReader wraps the KeyMaterial method exposed by Provider and Distributor
137// implementations. Defining the interface here makes it possible to use the

Calls 3

PathFunction · 0.92
FatalfMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected