diff --git a/comid/tdx-profile/*.cbor b/comid/tdx-profile/*.cbor deleted file mode 100644 index e69de29..0000000 diff --git a/comid/tdx-profile/example_pce_refval_test.go b/comid/tdx-profile/example_pce_refval_test.go index 795a37a..db99411 100644 --- a/comid/tdx-profile/example_pce_refval_test.go +++ b/comid/tdx-profile/example_pce_refval_test.go @@ -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) } diff --git a/comid/tdx-profile/example_qe_refval_test.go b/comid/tdx-profile/example_qe_refval_test.go index 47e419d..05a044b 100644 --- a/comid/tdx-profile/example_qe_refval_test.go +++ b/comid/tdx-profile/example_qe_refval_test.go @@ -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) } diff --git a/comid/tdx-profile/example_seam_refval_test.go b/comid/tdx-profile/example_seam_refval_test.go index 3744b82..c5cc3a4 100644 --- a/comid/tdx-profile/example_seam_refval_test.go +++ b/comid/tdx-profile/example_seam_refval_test.go @@ -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) } diff --git a/comid/tdx-profile/teeadvisoryids.go b/comid/tdx-profile/teeadvisoryids.go index e5d6e77..e8a437e 100644 --- a/comid/tdx-profile/teeadvisoryids.go +++ b/comid/tdx-profile/teeadvisoryids.go @@ -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 @@ -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 diff --git a/comid/tdx-profile/teeadvisoryids_test.go b/comid/tdx-profile/teeadvisoryids_test.go index bf31c89..d70cc6e 100644 --- a/comid/tdx-profile/teeadvisoryids_test.go +++ b/comid/tdx-profile/teeadvisoryids_test.go @@ -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] @@ -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] diff --git a/comid/tdx-profile/teeinstanceid.go b/comid/tdx-profile/teeinstanceid.go index b706505..a984bf0 100644 --- a/comid/tdx-profile/teeinstanceid.go +++ b/comid/tdx-profile/teeinstanceid.go @@ -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 { @@ -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 @@ -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 { @@ -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 @@ -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 @@ -114,6 +119,7 @@ func (o TeeInstanceID) IsUintTeeInstanceID() bool { } } +// MarshalJSON Marshals TeeInstanceID to JSON func (o TeeInstanceID) MarshalJSON() ([]byte, error) { if o.Valid() != nil { @@ -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 @@ -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) } diff --git a/comid/tdx-profile/teeisvproid.go b/comid/tdx-profile/teeisvproid.go index 6010c0c..8e28ff5 100644 --- a/comid/tdx-profile/teeisvproid.go +++ b/comid/tdx-profile/teeisvproid.go @@ -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 @@ -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 { @@ -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 @@ -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 @@ -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) }