Skip to content

Commit

Permalink
WIP: typechoice
Browse files Browse the repository at this point in the history
Signed-off-by: Sergei Trofimov <[email protected]>
  • Loading branch information
setrofim committed Oct 12, 2023
1 parent 1b125a1 commit 74befcd
Show file tree
Hide file tree
Showing 23 changed files with 1,204 additions and 523 deletions.
5 changes: 3 additions & 2 deletions comid/attestverifkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ func TestAttestVerifKey_Valid_empty(t *testing.T) {
testerr: "environment validation failed: environment must not be empty",
},
{
env: Environment{Instance: NewInstanceUEID(TestUEID)},
env: Environment{Instance: MustNewInstanceUEID(TestUEID)},
verifkey: CryptoKeys{},
testerr: "verification keys validation failed: no keys to validate",
},
{
env: Environment{Instance: NewInstanceUEID(TestUEID)},
env: Environment{Instance: MustNewInstanceUEID(TestUEID)},
verifkey: CryptoKeys{&invalidKey},
testerr: "verification keys validation failed: invalid key at index 0: key value not set",
},
}

for _, tv := range tvs {
av := AttestVerifKey{Environment: tv.env, VerifKeys: tv.verifkey}
err := av.Valid()
Expand Down
31 changes: 27 additions & 4 deletions comid/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package comid

import (
"fmt"
"reflect"

cbor "github.com/fxamacker/cbor/v2"
Expand All @@ -12,16 +13,14 @@ import (
var (
em, emError = initCBOREncMode()
dm, dmError = initCBORDecMode()
)

func comidTags() cbor.TagSet {
comidTagsMap := map[uint64]interface{}{
comidTagsMap = map[uint64]interface{}{
32: TaggedURI(""),
37: TaggedUUID{},
111: TaggedOID{},
// CoMID tags
550: TaggedUEID{},
//551: To Do see: https://github.com/veraison/corim/issues/32
551: TaggedInt(0),
552: TaggedSVN(0),
553: TaggedMinSVN(0),
554: TaggedPKIXBase64Key(""),
Expand All @@ -37,7 +36,9 @@ func comidTags() cbor.TagSet {
601: TaggedPSARefValID{},
602: TaggedCCAPlatformConfigID(""),
}
)

func comidTags() cbor.TagSet {
opts := cbor.TagOptions{
EncTag: cbor.EncTagRequired,
DecTag: cbor.DecTagRequired,
Expand Down Expand Up @@ -69,6 +70,28 @@ func initCBORDecMode() (dm cbor.DecMode, err error) {
return decOpt.DecModeWithTags(comidTags())
}

func registerCOMIDTag(tag uint64, t interface{}) error {
if _, exists := comidTagsMap[tag]; exists {
return fmt.Errorf("tag %d is already registered", tag)
}

comidTagsMap[tag] = t

var err error

em, err = initCBOREncMode()
if err != nil {
return err
}

dm, err = initCBORDecMode()
if err != nil {
return err
}

return nil
}

func init() {
if emError != nil {
panic(emError)
Expand Down
32 changes: 13 additions & 19 deletions comid/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,33 @@ type Class struct {
// NewClassUUID instantiates a new Class object with the specified UUID as
// identifier
func NewClassUUID(uuid UUID) *Class {
c := Class{
ClassID: &ClassID{},
}

if c.ClassID.SetUUID(uuid) == nil {
classID, err := NewUUIDClassID(uuid)
if err != nil {
return nil
}
return &c

return &Class{ClassID: classID}
}

// NewClassImplID instantiates a new Class object that identifies the specified PSA
// Implementation ID
func NewClassImplID(implID ImplID) *Class {
c := Class{
ClassID: &ClassID{},
}

if c.ClassID.SetImplID(implID) == nil {
classID, err := NewImplIDClassID(implID)
if err != nil {
return nil
}
return &c

return &Class{ClassID: classID}
}

// NewClassOID instantiates a new Class object that identifies the OID
func NewClassOID(oid string) *Class {
c := Class{
ClassID: &ClassID{},
}

if c.ClassID.SetOID(oid) == nil {
classID, err := NewOIDClassID(oid)
if err != nil {
return nil
}
return &c

return &Class{ClassID: classID}
}

// SetVendor sets the vendor metadata to the supplied string
Expand Down Expand Up @@ -131,7 +125,7 @@ func (o *Class) SetIndex(index uint64) *Class {
// Valid checks the non-empty<> constraint on the map
func (o Class) Valid() error {
// check non-empty<{ ... }>
if (o.ClassID == nil || o.ClassID.Unset()) &&
if (o.ClassID == nil || !o.ClassID.IsSet()) &&
o.Vendor == nil && o.Model == nil && o.Layer == nil && o.Index == nil {
return fmt.Errorf("class must not be empty")
}
Expand Down
Loading

0 comments on commit 74befcd

Please sign in to comment.