Skip to content

Commit c1870a5

Browse files
committed
Use fmt.Sprintf for fixed-format PCR JSON in nitrofake
1 parent 1008fcc commit c1870a5

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

  • pkg/teeattestation/nitro/fake

pkg/teeattestation/nitro/fake/fake.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"crypto/x509"
1313
"crypto/x509/pkix"
1414
"encoding/hex"
15-
"encoding/json"
1615
"encoding/pem"
1716
"fmt"
1817
"math/big"
@@ -174,14 +173,11 @@ func (f *Attestor) CARootsPEM() string {
174173
// TrustedPCRsJSON returns the PCR values as a JSON object matching the
175174
// format expected by the attestation validator.
176175
func (f *Attestor) TrustedPCRsJSON() []byte {
177-
m := map[string]string{
178-
"pcr0": hex.EncodeToString(f.pcrs[0]),
179-
"pcr1": hex.EncodeToString(f.pcrs[1]),
180-
"pcr2": hex.EncodeToString(f.pcrs[2]),
181-
}
182-
// json.Marshal on map[string]string cannot fail.
183-
b, _ := json.Marshal(m)
184-
return b
176+
return []byte(fmt.Sprintf(`{"pcr0":"%s","pcr1":"%s","pcr2":"%s"}`,
177+
hex.EncodeToString(f.pcrs[0]),
178+
hex.EncodeToString(f.pcrs[1]),
179+
hex.EncodeToString(f.pcrs[2]),
180+
))
185181
}
186182

187183
func sha384Sum(data []byte) []byte {

0 commit comments

Comments
 (0)