Skip to content

Commit

Permalink
Incorprated few review comments!
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed Jan 30, 2025
1 parent ea4c4da commit a7bf34f
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 31 deletions.
Empty file removed comid/tdx-profile/*.cbor
Empty file.
8 changes: 4 additions & 4 deletions comid/tdx-profile/example_pce_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ func decodePCEMValExtensions(m *comid.Measurement) error {
fmt.Printf("val was not pointer to teeInstanceID")
}

if i.IsBytesTeeInstanceID() {
val, err = i.GetBytesTeeInstanceID()
if i.IsBytes() {
val, err = i.GetBytes()
if err != nil {
return fmt.Errorf("failed to decode teeinstanceid: %w", err)
}
fmt.Printf("\nInstanceID: %x", val)
} else if i.IsUintTeeInstanceID() {
val, err = i.GetUintTeeInstanceID()
} else if i.IsUint() {
val, err = i.GetUint()
if err != nil {
return fmt.Errorf("failed to decode teeinstanceid: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions comid/tdx-profile/example_qe_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ func decodeQEMValExtensions(m *comid.Measurement) error {
fmt.Printf("val was not pointer to IsvProdID")
}

if tS.IsBytesTeeISVProdID() {
val, err = tS.GetBytesTeeISVProdID()
if tS.IsBytes() {
val, err = tS.GetBytes()
if err != nil {
return fmt.Errorf("failed to decode isvprodid: %w", err)
}
fmt.Printf("\nIsvProdID: %x", val)
} else if tS.IsUintTeeISVProdID() {
val, err = tS.GetUintTeeISVProdID()
} else if tS.IsUint() {
val, err = tS.GetUint()
if err != nil {
return fmt.Errorf("failed to decode isvprodid: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions comid/tdx-profile/example_seam_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ func decodeMValExtensions(m *comid.Measurement) error {
if !ok {
fmt.Printf("val was not pointer to IsvProdID")
}
if tS.IsBytesTeeISVProdID() {
val, err = tS.GetBytesTeeISVProdID()
if tS.IsBytes() {
val, err = tS.GetBytes()
if err != nil {
return fmt.Errorf("failed to decode isvprodid: %w", err)
}
fmt.Printf("\nIsvProdID: %x", val)
} else if tS.IsUintTeeISVProdID() {
val, err = tS.GetUintTeeISVProdID()
} else if tS.IsUint() {
val, err = tS.GetUint()
if err != nil {
return fmt.Errorf("failed to decode isvprodid: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions comid/tdx-profile/teeadvisoryids.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func NewTeeAvisoryIDs(val []any) *TeeAdvisoryIDs {

// AddTeeAdvisoryIDs add supplied AvisoryIDs to existing AdvisoryIDs
func (o *TeeAdvisoryIDs) AddTeeAdvisoryIDs(val []any) error {
for _, v := range val {
for i, v := range val {
switch t := v.(type) {
case string:
*o = append(*o, t)
default:
return fmt.Errorf("invalid type: %T for AdvisoryIDs", t)
return fmt.Errorf("invalid type: %T for AdvisoryIDs at index: %d", t, i)
}
}
return nil
Expand All @@ -46,12 +46,12 @@ func (o TeeAdvisoryIDs) Valid() error {
return fmt.Errorf("empty AdvisoryIDs")

}
for _, v := range o {
for i, v := range o {
switch t := v.(type) {
case string:
continue
default:
return fmt.Errorf("invalid type: %T for AdvisoryIDs", t)
return fmt.Errorf("invalid type: %T for AdvisoryIDs at index: %d", t, i)
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions comid/tdx-profile/teeadvisoryids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestAdvisoryIDs_AddAdvisoryIDs_OK(t *testing.T) {
}

func TestAdvisoryIDs_AddAdvisoryIDs_NOK(t *testing.T) {
expectedErr := "invalid type: float64 for AdvisoryIDs"
expectedErr := "invalid type: float64 for AdvisoryIDs at index: 0"
s := make([]any, len(TestInvalidAdvisoryIDs))
for i := range TestInvalidAdvisoryIDs {
s[i] = TestInvalidAdvisoryIDs[i]
Expand All @@ -61,7 +61,7 @@ func TestAdvisoryIDs_Valid_NOK(t *testing.T) {
err := adv.Valid()
assert.EqualError(t, err, expectedErr)

expectedErr = "invalid type: float64 for AdvisoryIDs"
expectedErr = "invalid type: float64 for AdvisoryIDs at index: 0"
s := make([]any, len(TestInvalidAdvisoryIDs))
for i := range TestInvalidAdvisoryIDs {
s[i] = TestInvalidAdvisoryIDs[i]
Expand Down
20 changes: 15 additions & 5 deletions comid/tdx-profile/teeinstanceid.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type TeeInstanceID struct {
val interface{}
}

// NewteeInstanceID creates a new InstanceID from the
// NewTeeInstanceID creates a new InstanceID from the
// supplied interface. The supported types are positive integers and
// byte array
func NewTeeInstanceID(val interface{}) *TeeInstanceID {
Expand Down Expand Up @@ -74,7 +74,8 @@ func (o TeeInstanceID) Valid() error {
return nil
}

func (o TeeInstanceID) GetUintTeeInstanceID() (uint, error) {
// GetUint returns unsigned integer TeeInstanceID
func (o TeeInstanceID) GetUint() (uint, error) {
switch t := o.val.(type) {
case uint64:
return uint(t), nil
Expand All @@ -85,7 +86,8 @@ func (o TeeInstanceID) GetUintTeeInstanceID() (uint, error) {
}
}

func (o TeeInstanceID) GetBytesTeeInstanceID() ([]byte, error) {
// GetBytes returns the bytes TeeInstanceID
func (o TeeInstanceID) GetBytes() ([]byte, error) {
switch t := o.val.(type) {
case []byte:
if len(t) == 0 {
Expand All @@ -96,7 +98,9 @@ func (o TeeInstanceID) GetBytesTeeInstanceID() ([]byte, error) {
return nil, fmt.Errorf("TeeInstanceID type is: %T", t)
}
}
func (o TeeInstanceID) IsBytesTeeInstanceID() bool {

// IsBytes returns true if TeeInstanceID is of type []byte array
func (o TeeInstanceID) IsBytes() bool {
switch o.val.(type) {
case []byte:
return true
Expand All @@ -105,7 +109,8 @@ func (o TeeInstanceID) IsBytesTeeInstanceID() bool {
}
}

func (o TeeInstanceID) IsUintTeeInstanceID() bool {
// IsUnit returns true if TeeInstanceID is of type unsigned integer
func (o TeeInstanceID) IsUint() bool {
switch o.val.(type) {
case uint64, uint:
return true
Expand All @@ -114,6 +119,7 @@ func (o TeeInstanceID) IsUintTeeInstanceID() bool {
}
}

// MarshalJSON Marshals TeeInstanceID to JSON
func (o TeeInstanceID) MarshalJSON() ([]byte, error) {

if o.Valid() != nil {
Expand Down Expand Up @@ -143,6 +149,7 @@ func (o TeeInstanceID) MarshalJSON() ([]byte, error) {
return json.Marshal(v)
}

// UnmarshalJSON UnMarshals supplied JSON bytes to TeeInstanceID
func (o *TeeInstanceID) UnmarshalJSON(data []byte) error {
var v encoding.TypeAndValue

Expand All @@ -168,10 +175,13 @@ func (o *TeeInstanceID) UnmarshalJSON(data []byte) error {
}
return nil
}

// MarshalCBOR Marshals TeeInstanceID to CBOR
func (o TeeInstanceID) MarshalCBOR() ([]byte, error) {
return cbor.Marshal(o.val)
}

// UnmarshalCBOR UnMarshals supplied CBOR bytes to TeeInstanceID
func (o *TeeInstanceID) UnmarshalCBOR(data []byte) error {
return cbor.Unmarshal(data, &o.val)
}
18 changes: 10 additions & 8 deletions comid/tdx-profile/teeisvproid.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func (o TeeISVProdID) Valid() error {
return nil
}

// GetUintTeeISVProdID returns a uint TeeISVProdID
func (o TeeISVProdID) GetUintTeeISVProdID() (uint, error) {
// GetUint returns a uint TeeISVProdID
func (o TeeISVProdID) GetUint() (uint, error) {
switch t := o.val.(type) {
case uint64:
return uint(t), nil
Expand All @@ -86,8 +86,8 @@ func (o TeeISVProdID) GetUintTeeISVProdID() (uint, error) {
}
}

// GetBytesTeeISVProdID returns a []byte TeeISVProdID
func (o TeeISVProdID) GetBytesTeeISVProdID() ([]byte, error) {
// GetBytes returns a []byte TeeISVProdID
func (o TeeISVProdID) GetBytes() ([]byte, error) {
switch t := o.val.(type) {
case []byte:
if len(t) == 0 {
Expand All @@ -99,8 +99,8 @@ func (o TeeISVProdID) GetBytesTeeISVProdID() ([]byte, error) {
}
}

// IsBytesTeeISVProdID returns true if TeeISVProdID is a byte array
func (o TeeISVProdID) IsBytesTeeISVProdID() bool {
// IsBytes returns true if TeeISVProdID is a byte array
func (o TeeISVProdID) IsBytes() bool {
switch o.val.(type) {
case []byte:
return true
Expand All @@ -109,8 +109,8 @@ func (o TeeISVProdID) IsBytesTeeISVProdID() bool {
}
}

// IsBytesTeeISVProdID returns true if TeeISVProdID is a positive integer
func (o TeeISVProdID) IsUintTeeISVProdID() bool {
// IsUint returns true if TeeISVProdID is a positive integer
func (o TeeISVProdID) IsUint() bool {
switch t := o.val.(type) {
case uint64, uint:
return true
Expand Down Expand Up @@ -180,10 +180,12 @@ func (o *TeeISVProdID) UnmarshalJSON(data []byte) error {
return nil
}

// MarshalCBOR Marshals TeeISVProdID to CBOR bytes
func (o TeeISVProdID) MarshalCBOR() ([]byte, error) {
return cbor.Marshal(o.val)
}

// UnmarshalCBOR UnMarshals supplied CBOR bytes to TeeISVProdID
func (o *TeeISVProdID) UnmarshalCBOR(data []byte) error {
return cbor.Unmarshal(data, &o.val)
}

0 comments on commit a7bf34f

Please sign in to comment.