Skip to content

Commit 9f5d375

Browse files
committed
fix(kds/TCBVersion): add a String() method
Add a String() method to TCBVersion Signed-off-by: Jagannathan Raman <jraman567@gmail.com>
1 parent 45e5196 commit 9f5d375

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

kds/kds.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ type TCBVersion struct {
135135
TCB uint64
136136
}
137137

138+
// String returns the version of the TCB in string format
139+
func (v TCBVersion) String() string {
140+
switch v.Version {
141+
case TCBStructVersion0:
142+
return fmt.Sprintf("Milan or Genoa TCB: 0x%x", v.TCB)
143+
case TCBHwIDLenVersion1:
144+
return fmt.Sprintf("Turin TCB: 0x%x", v.TCB)
145+
default:
146+
return "Unknown TCB"
147+
}
148+
}
149+
138150
// Extensions represents the information stored in the KDS-specified x509 extensions of a V{C,L}EK
139151
// certificate.
140152
type Extensions struct {

validate/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ func tcbNeError(left, right partDescription) error {
431431
if ltcb == rtcb {
432432
return nil
433433
}
434-
return fmt.Errorf("the %s 0x%x does not match the %s 0x%x", left.desc, ltcb.TCB, right.desc, rtcb.TCB)
434+
return fmt.Errorf("the %s %s does not match the %s %s", left.desc, ltcb.String(), right.desc, rtcb.String())
435435
}
436436

437437
// tcbGtError returns an error if wantLower is greater than (in part) wantHigher. It enforces

validate/validate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func TestValidateSnpAttestation(t *testing.T) {
418418
name: "rejected provisional by tcb",
419419
attestation: attestationcb1455,
420420
opts: &Options{ReportData: noncecb1455[:], GuestPolicy: abi.SnpPolicy{Debug: true}},
421-
wantErr: "the report's COMMITTED_TCB 0x9270000000007f00 does not match the report's CURRENT_TCB 0x9270000000007f1f",
421+
wantErr: "the report's COMMITTED_TCB Milan or Genoa TCB: 0x9270000000007f00 does not match the report's CURRENT_TCB Milan or Genoa TCB: 0x9270000000007f1f",
422422
},
423423
{
424424
name: "accepted provisional by version",

0 commit comments

Comments
 (0)