Skip to content

Commit

Permalink
WIP BORKED
Browse files Browse the repository at this point in the history
  • Loading branch information
setrofim committed Oct 25, 2023
1 parent 97aeb90 commit 786cb00
Show file tree
Hide file tree
Showing 8 changed files with 442 additions and 407 deletions.
57 changes: 54 additions & 3 deletions comid/ccaplatformconfigid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

package comid

import "fmt"
import (
"errors"
"fmt"
"unicode/utf8"
)

type CCAPlatformConfigID string
var CCAPlatformConfigIDType = "cca.platform-config-id"

type TaggedCCAPlatformConfigID CCAPlatformConfigID
type CCAPlatformConfigID string

func (o CCAPlatformConfigID) Empty() bool {
return o == ""
Expand All @@ -27,3 +31,50 @@ func (o CCAPlatformConfigID) Get() (CCAPlatformConfigID, error) {
}
return o, nil
}

type TaggedCCAPlatformConfigID CCAPlatformConfigID

func NewTaggedCCAPlatormConfigID(val any) (*TaggedCCAPlatformConfigID, error) {
var ret TaggedCCAPlatformConfigID
switch t := val.(type) {
case TaggedCCAPlatformConfigID:
ret = t
case *TaggedCCAPlatformConfigID:
ret = *t
case CCAPlatformConfigID:
ret = TaggedCCAPlatformConfigID(t)
case *CCAPlatformConfigID:
ret = TaggedCCAPlatformConfigID(*t)
case string:
ret = TaggedCCAPlatformConfigID(t)
case []byte:
if !utf8.Valid(t) {
return nil, errors.New("bytes do not form a valid UTF-8 string")
}
ret = TaggedCCAPlatformConfigID(t)
default:
return nil, fmt.Errorf("unexpected type for CCA platform-config-id: %T", t)
}

return &ret, nil
}

func (o TaggedCCAPlatformConfigID) Valid() error {
if o == "" {
return errors.New("empty")
}

return nil
}

func (o TaggedCCAPlatformConfigID) String() string {
return string(o)
}

func (o TaggedCCAPlatformConfigID) Type() string {
return CCAPlatformConfigIDType
}

func (o TaggedCCAPlatformConfigID) IsZero() bool {
return len(o) == 0
}
18 changes: 10 additions & 8 deletions comid/example_cca_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,23 @@ func extractCCARefVal(rv ReferenceValue) error {
if !m.Key.IsSet() {
return fmt.Errorf("mKey not set at index %d", i)
}
if m.Key.IsPSARefValID() {

switch t := m.Key.Value.(type) {
case TaggedPSARefValID:
if err := extractSwMeasurement(m); err != nil {
return fmt.Errorf("extracting measurement at index %d: %w", i, err)
}
}
if m.Key.IsCCAPlatformConfigID() {
case TaggedCCAPlatformConfigID:
if err := extractCCARefValID(m.Key); err != nil {
return fmt.Errorf("extracting cca-refval-id: %w", err)
}
if err := extractRawValue(m.Val.RawValue); err != nil {
return fmt.Errorf("extracting raw vlue: %w", err)
}

return nil
default:
return fmt.Errorf("unexpected Mkey type: %T", t)
}

}

return nil
Expand All @@ -105,9 +107,9 @@ func extractCCARefValID(k *Mkey) error {
return fmt.Errorf("no measurement key")
}

id, err := k.GetCCAPlatformConfigID()
if err != nil {
return fmt.Errorf("getting CCA platform config id: %w", err)
id, ok := k.Value.(TaggedCCAPlatformConfigID)
if !ok {
return fmt.Errorf("expected CCA platform config id, found: %T", k.Value)
}
fmt.Printf("Label: %s\n", id)
return nil
Expand Down
6 changes: 3 additions & 3 deletions comid/example_psa_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func extractPSARefValID(k *Mkey) error {
return fmt.Errorf("no measurement key")
}

id, err := k.GetPSARefValID()
if err != nil {
return fmt.Errorf("getting PSA refval id: %w", err)
id, ok := k.Value.(TaggedPSARefValID)
if !ok {
return fmt.Errorf("expected PSA refval id, found: %T", k.Value)
}

fmt.Printf("SignerID: %x\n", id.SignerID)
Expand Down
24 changes: 10 additions & 14 deletions comid/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func Example_encode() {
},
Measurements: *NewMeasurements().
AddMeasurement(
NewMeasurement().
SetKeyUUID(TestUUID).
MustNewUUIDMeasurement(TestUUID).
SetRawValueBytes([]byte{0x01, 0x02, 0x03, 0x04}, []byte{0xff, 0xff, 0xff, 0xff}).
SetSVN(2).
AddDigest(swid.Sha256_32, []byte{0xab, 0xcd, 0xef, 0x00}).
Expand Down Expand Up @@ -60,8 +59,7 @@ func Example_encode() {
},
Measurements: *NewMeasurements().
AddMeasurement(
NewMeasurement().
SetKeyUUID(TestUUID).
MustNewUUIDMeasurement(TestUUID).
SetRawValueBytes([]byte{0x01, 0x02, 0x03, 0x04}, []byte{0xff, 0xff, 0xff, 0xff}).
SetMinSVN(2).
AddDigest(swid.Sha256_32, []byte{0xab, 0xcd, 0xef, 0x00}).
Expand Down Expand Up @@ -126,18 +124,16 @@ func Example_encode_PSA() {
},
Measurements: *NewMeasurements().
AddMeasurement(
NewPSAMeasurement(
*NewPSARefValID(TestSignerID).
SetLabel("BL").
SetVersion("5.0.5"),
).AddDigest(swid.Sha256_32, []byte{0xab, 0xcd, 0xef, 0x00}),
MustNewPSAMeasurement(
MustCreatePSARefValID(
TestSignerID, "BL", "5.0.5",
)).AddDigest(swid.Sha256_32, []byte{0xab, 0xcd, 0xef, 0x00}),
).
AddMeasurement(
NewPSAMeasurement(
*NewPSARefValID(TestSignerID).
SetLabel("PRoT").
SetVersion("1.3.5"),
).AddDigest(swid.Sha256_32, []byte{0xab, 0xcd, 0xef, 0x00}),
MustNewPSAMeasurement(
MustCreatePSARefValID(
TestSignerID, "PRoT", "1.3.5",
)).AddDigest(swid.Sha256_32, []byte{0xab, 0xcd, 0xef, 0x00}),
),
},
).
Expand Down
Loading

0 comments on commit 786cb00

Please sign in to comment.