From cb2d487eb3b4d68a36dce9f89bd084a4a9418d11 Mon Sep 17 00:00:00 2001 From: Yogesh Deshpande Date: Fri, 24 Jan 2025 13:15:57 +0000 Subject: [PATCH] Changed instance identifier Signed-off-by: Yogesh Deshpande --- comid/tdx-profile/instanceid.go | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/comid/tdx-profile/instanceid.go b/comid/tdx-profile/instanceid.go index 3731fbf..7eb4f72 100644 --- a/comid/tdx-profile/instanceid.go +++ b/comid/tdx-profile/instanceid.go @@ -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 } @@ -32,14 +32,14 @@ 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) } @@ -47,10 +47,10 @@ func (o *InstanceID) SetInstanceID(val interface{}) error { } 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: @@ -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: @@ -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") @@ -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: @@ -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: @@ -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 { @@ -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) }