Skip to content

Commit

Permalink
Further work!
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed Apr 16, 2024
1 parent 1b286cd commit 12f0c9d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
43 changes: 43 additions & 0 deletions comid/classid.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,55 @@ func (o ClassID) String() string {
return o.Value.String()
}

// SetImplID sets the value of the target ClassID to the supplied PSA
// Implementation ID (see Section 3.2.2 of draft-tschofenig-rats-psa-token)
func (o *ClassID) SetImplID(implID ImplID) *ClassID {
if o != nil {
o.Value = TaggedImplID(implID)
}
return o
}

// GetImplID retrieves the value of the PSA Implementation ID
// (see Section 3.2.2 of draft-tschofenig-rats-psa-token) from ClassID
func (o ClassID) GetImplID() (ImplID, error) {
switch t := o.Value.(type) {
case *TaggedImplID:
return ImplID(*t), nil
case TaggedImplID:
return ImplID(t), nil
default:
return ImplID{}, fmt.Errorf("class-id type is: %T", t)
}
}

type IClassIDValue interface {
extensions.ITypeChoiceValue

Bytes() []byte
}

// SetUUID sets the value of the target ClassID to the supplied UUID
func (o *ClassID) SetUUID(uuid UUID) *ClassID {
if o != nil {
o.Value = TaggedUUID(uuid)
}
return o
}

// SetOID sets the value of the targed ClassID to the supplied OID.
// The OID is a string in dotted-decimal notation
func (o *ClassID) SetOID(s string) *ClassID {
if o != nil {
var berOID OID
if berOID.FromString(s) != nil {
return nil
}
o.Value = TaggedOID(berOID)
}
return o
}

const ImplIDType = "psa.impl-id"

type ImplID [32]byte
Expand Down
41 changes: 41 additions & 0 deletions comid/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"encoding/json"
"fmt"

"github.com/google/uuid"
"github.com/veraison/corim/encoding"
"github.com/veraison/corim/extensions"
"github.com/veraison/eat"
)

// Instance stores an instance identity. The supported formats are UUID, UEID and variable-length opaque bytes.
Expand Down Expand Up @@ -121,6 +123,45 @@ func (o Instance) MarshalJSON() ([]byte, error) {
return json.Marshal(value)
}

// SetUEID sets the identity of the target instance to the supplied UEID
func (o *Instance) SetUEID(val eat.UEID) *Instance {
if o != nil {
if val.Validate() != nil {
return nil
}
o.Value = TaggedUEID(val)
}
return o
}

// SetUUID sets the identity of the target instance to the supplied UUID
func (o *Instance) SetUUID(val uuid.UUID) *Instance {
if o != nil {
o.Value = TaggedUUID(val)
}
return o
}

func (o Instance) GetUEID() (eat.UEID, error) {
switch t := o.Value.(type) {
case TaggedUEID:
return eat.UEID(t), nil
default:
return eat.UEID{}, fmt.Errorf("instance-id type is: %T", t)
}
}

func (o Instance) GetUUID() (UUID, error) {
switch t := o.Value.(type) {
case *TaggedUUID:
return UUID(*t), nil
case TaggedUUID:
return UUID(t), nil
default:
return UUID{}, fmt.Errorf("instance-id type is: %T", t)
}
}

// IInstanceValue is the interface implemented by all Instance value
// implementations.
type IInstanceValue interface {
Expand Down
14 changes: 11 additions & 3 deletions comid/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ import (

func TestInstance_GetUUID_OK(t *testing.T) {
inst := MustNewUUIDInstance(TestUUID)
u, ok := inst.Value.(*TaggedUUID)
assert.True(t, ok)
assert.EqualValues(t, TestUUID, *u)
require.NotNil(t, inst)
u, err := inst.GetUUID()
assert.Nil(t, err)
assert.Equal(t, u, TestUUID)
}

func TestInstance_GetUUID_NOK(t *testing.T) {
inst := &Instance{}
expectedErr := "instance-id type is: <nil>"
_, err := inst.GetUUID()
assert.EqualError(t, err, expectedErr)
}

type testInstance string
Expand Down
5 changes: 5 additions & 0 deletions comid/measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func (o Mkey) GetPSARefValID() (PSARefValID, error) {
return PSARefValID{}, errors.New("MKey is not set")
}
switch t := o.Value.(type) {
case *TaggedPSARefValID:
return PSARefValID(*t), nil
case TaggedPSARefValID:
return PSARefValID(t), nil
default:
Expand All @@ -87,7 +89,10 @@ func (o Mkey) GetCCAPlatformConfigID() (CCAPlatformConfigID, error) {
if !o.IsSet() {
return "", errors.New("MKey is not set")
}

switch t := o.Value.(type) {
case *TaggedCCAPlatformConfigID:
return CCAPlatformConfigID(*t), nil
case TaggedCCAPlatformConfigID:
return CCAPlatformConfigID(t), nil
default:
Expand Down

0 comments on commit 12f0c9d

Please sign in to comment.