Skip to content

Commit

Permalink
Changed instance identifier
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed Jan 24, 2025
1 parent e9a7bf5 commit cb2d487
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions comid/tdx-profile/instanceid.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import (

// InstanceID stores an TEE Instance Identifier. The supported formats are uint and variable-length bytes.
type InstanceID struct {
Value interface{}
val interface{}
}

func NewInstanceID(val interface{}) *InstanceID {
switch t := val.(type) {
case uint, uint64:
return &InstanceID{Value: t}
return &InstanceID{val: t}
case []byte:
return &InstanceID{Value: t}
return &InstanceID{val: t}
case int:
if t < 0 {
return nil
}
return &InstanceID{Value: t}
return &InstanceID{val: t}
default:
return nil
}
Expand All @@ -32,25 +32,25 @@ func NewInstanceID(val interface{}) *InstanceID {
func (o *InstanceID) SetInstanceID(val interface{}) error {
switch t := val.(type) {
case uint, uint64:
o.Value = val
o.val = val
case []byte:
o.Value = val
o.val = val
case int:
if t < 0 {
return fmt.Errorf("unsupported negative InstanceID: %d", t)
}
o.Value = val
o.val = val
default:
return fmt.Errorf("unsupported InstanceID type: %T", t)
}
return nil
}

func (o InstanceID) Valid() error {
if o.Value == nil {
if o.val == nil {
return fmt.Errorf("empty InstanceID")
}
switch t := o.Value.(type) {
switch t := o.val.(type) {
case uint, uint64:
return nil
case []byte:
Expand All @@ -66,7 +66,7 @@ func (o InstanceID) Valid() error {
}

func (o InstanceID) GetUintInstanceID() (uint, error) {
switch t := o.Value.(type) {
switch t := o.val.(type) {
case uint64:
return uint(t), nil
case uint:
Expand All @@ -77,7 +77,7 @@ func (o InstanceID) GetUintInstanceID() (uint, error) {
}

func (o InstanceID) GetBytesInstanceID() ([]byte, error) {
switch t := o.Value.(type) {
switch t := o.val.(type) {
case []byte:
if len(t) == 0 {
return nil, fmt.Errorf("InstanceID type is of zero length")
Expand All @@ -88,7 +88,7 @@ func (o InstanceID) GetBytesInstanceID() ([]byte, error) {
}
}
func (o InstanceID) IsBytesInstanceID() bool {
switch o.Value.(type) {
switch o.val.(type) {
case []byte:
return true
default:
Expand All @@ -97,7 +97,7 @@ func (o InstanceID) IsBytesInstanceID() bool {
}

func (o InstanceID) IsUintInstanceID() bool {
switch o.Value.(type) {
switch o.val.(type) {
case uint64, uint:
return true
default:
Expand All @@ -115,7 +115,7 @@ func (o InstanceID) MarshalJSON() ([]byte, error) {
b []byte
err error
)
switch t := o.Value.(type) {
switch t := o.val.(type) {
case uint, uint64, int:
b, err = json.Marshal(t)
if err != nil {
Expand Down Expand Up @@ -148,21 +148,21 @@ func (o *InstanceID) UnmarshalJSON(data []byte) error {
return fmt.Errorf(
"cannot unmarshal InstanceID of type uint: %w", err)
}
o.Value = x
o.val = x
case "bytes":
var x []byte
if err := json.Unmarshal(v.Value, &x); err != nil {
return fmt.Errorf(
"cannot unmarshal InstanceID of type bytes: %w", err)
}
o.Value = x
o.val = x
}
return nil
}
func (o InstanceID) MarshalCBOR() ([]byte, error) {
return cbor.Marshal(o.Value)
return cbor.Marshal(o.val)
}

func (o *InstanceID) UnmarshalCBOR(data []byte) error {
return cbor.Unmarshal(data, &o.Value)
return cbor.Unmarshal(data, &o.val)
}

0 comments on commit cb2d487

Please sign in to comment.