Skip to content

Commit

Permalink
merging-extra-lint
Browse files Browse the repository at this point in the history
Signed-off-by: Akhilesh Kr. Yadav <[email protected]>
  • Loading branch information
Akhilesh Kr. Yadav authored and Akhilesh Kr. Yadav committed Jan 15, 2025
1 parent 7e33dd8 commit eef777e
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 44 deletions.
20 changes: 12 additions & 8 deletions comid/comid.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ func (o *Comid) AddDevIdentityKey(val KeyTriple) *Comid {
return o
}

func (o *Comid) Valid() error {
// nolint:gocritic
func (o Comid) Valid() error {
if err := o.TagIdentity.Valid(); err != nil {
return fmt.Errorf("tag-identity validation failed: %w", err)
}
Expand All @@ -263,11 +264,12 @@ func (o *Comid) Valid() error {
return fmt.Errorf("triples validation failed: %w", err)
}

return o.Extensions.validComid(o)
return o.Extensions.validComid(&o)
}

// ToCBOR serializes the target Comid to CBOR
func (o *Comid) ToCBOR() ([]byte, error) {
// nolint:gocritic
func (o Comid) ToCBOR() ([]byte, error) {
if err := o.Valid(); err != nil {
return nil, err
}
Expand All @@ -282,7 +284,7 @@ func (o *Comid) ToCBOR() ([]byte, error) {
o.Entities = nil
}

return encoding.SerializeStructToCBOR(em, o)
return encoding.SerializeStructToCBOR(em, &o)
}

// FromCBOR deserializes a CBOR-encoded CoMID into the target Comid
Expand All @@ -291,7 +293,8 @@ func (o *Comid) FromCBOR(data []byte) error {
}

// ToJSON serializes the target Comid to JSON
func (o *Comid) ToJSON() ([]byte, error) {
// nolint:gocritic
func (o Comid) ToJSON() ([]byte, error) {
if err := o.Valid(); err != nil {
return nil, err
}
Expand All @@ -306,18 +309,19 @@ func (o *Comid) ToJSON() ([]byte, error) {
o.Entities = nil
}

return encoding.SerializeStructToJSON(o)
return encoding.SerializeStructToJSON(&o)
}

// FromJSON deserializes a JSON-encoded CoMID into the target Comid
func (o *Comid) FromJSON(data []byte) error {
return encoding.PopulateStructFromJSON(data, o)
}

func (o *Comid) ToJSONPretty(indent string) ([]byte, error) {
// nolint:gocritic
func (o Comid) ToJSONPretty(indent string) ([]byte, error) {
if err := o.Valid(); err != nil {
return nil, err
}

return json.MarshalIndent(o, "", indent)
return json.MarshalIndent(&o, "", indent)
}
15 changes: 10 additions & 5 deletions comid/flagsmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ type FlagsMap struct {
func NewFlagsMap() *FlagsMap {
return &FlagsMap{}
}
func (o *FlagsMap) IsEmpty() bool {

// nolint:gocritic
func (o FlagsMap) IsEmpty() bool {
if o.IsConfigured != nil || o.IsSecure != nil || o.IsRecovery != nil ||
o.IsDebug != nil || o.IsReplayProtected != nil || o.IsIntegrityProtected != nil ||
o.IsRuntimeMeasured != nil || o.IsImmutable != nil || o.IsTcb != nil {
Expand Down Expand Up @@ -202,7 +204,8 @@ func (o *FlagsMap) UnmarshalCBOR(data []byte) error {
}

// MarshalCBOR serializes to CBOR
func (o *FlagsMap) MarshalCBOR() ([]byte, error) {
// nolint:gocritic
func (o FlagsMap) MarshalCBOR() ([]byte, error) {
return encoding.SerializeStructToCBOR(em, o)
}

Expand All @@ -212,11 +215,13 @@ func (o *FlagsMap) UnmarshalJSON(data []byte) error {
}

// MarshalJSON serializes to JSON
func (o *FlagsMap) MarshalJSON() ([]byte, error) {
// nolint:gocritic
func (o FlagsMap) MarshalJSON() ([]byte, error) {
return encoding.SerializeStructToJSON(o)
}

// Valid returns an error if the FlagsMap is invalid.
func (o *FlagsMap) Valid() error {
return o.Extensions.validFlagsMap(o)
// nolint:gocritic
func (o FlagsMap) Valid() error {
return o.Extensions.validFlagsMap(&o)
}
17 changes: 11 additions & 6 deletions comid/measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ func (o *Mval) UnmarshalCBOR(data []byte) error {
}

// MarshalCBOR serializes to CBOR
func (o *Mval) MarshalCBOR() ([]byte, error) {
// nolint:gocritic
func (o Mval) MarshalCBOR() ([]byte, error) {
// If extensions have been registered, the collection will exist, but
// might be empty. If that is the case, set it to nil to avoid
// marshaling an empty list (and let the marshaller omit the claim
Expand All @@ -409,7 +410,8 @@ func (o *Mval) UnmarshalJSON(data []byte) error {
}

// MarshalJSON serializes to JSON
func (o *Mval) MarshalJSON() ([]byte, error) {
// nolint:gocritic
func (o Mval) MarshalJSON() ([]byte, error) {
// If extensions have been registered, the collection will exist, but
// might be empty. If that is the case, set it to nil to avoid
// marshaling an empty list (and let the marshaller omit the claim
Expand All @@ -423,7 +425,8 @@ func (o *Mval) MarshalJSON() ([]byte, error) {
return encoding.SerializeStructToJSON(o)
}

func (o *Mval) Valid() error {
// nolint:gocritic
func (o Mval) Valid() error {
// Check if no measurement values are set
if o.Ver == nil &&
o.SVN == nil &&
Expand Down Expand Up @@ -481,7 +484,7 @@ func (o *Mval) Valid() error {
// raw value and raw-value-mask have no specific semantics here

// Validate extensions (custom logic implemented in validMval())
return o.Extensions.validMval(o)
return o.Extensions.validMval(&o)
}

// Version stores a version-map with JSON and CBOR serializations.
Expand Down Expand Up @@ -629,7 +632,8 @@ func (o *Measurement) RegisterExtensions(exts extensions.Map) error {
return o.Val.RegisterExtensions(exts)
}

func (o *Measurement) GetExtensions() extensions.IMapValue {
// nolint:gocritic
func (o Measurement) GetExtensions() extensions.IMapValue {
return o.Val.GetExtensions()
}

Expand Down Expand Up @@ -784,7 +788,8 @@ func (o *Measurement) SetUUID(u UUID) *Measurement {
return o
}

func (o *Measurement) Valid() error {
// nolint:gocritic
func (o Measurement) Valid() error {
if o.Key != nil && o.Key.IsSet() {
if err := o.Key.Valid(); err != nil {
return err
Expand Down
14 changes: 9 additions & 5 deletions corim/unsignedcorim.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func (o *UnsignedCorim) SetID(v interface{}) *UnsignedCorim {
}

// GetID retrieves the corim-id from the unsigned-corim-map as a string
func (o *UnsignedCorim) GetID() string {
// nolint:gocritic
func (o UnsignedCorim) GetID() string {
return o.ID.String()
}

Expand Down Expand Up @@ -232,7 +233,8 @@ func (o *UnsignedCorim) AddEntity(name string, regID *string, roles ...Role) *Un
}

// Valid checks the validity (according to the spec) of the target unsigned CoRIM
func (o *UnsignedCorim) Valid() error {
// nolint:gocritic
func (o UnsignedCorim) Valid() error {
if o.ID == (swid.TagID{}) {
return fmt.Errorf("empty id")
}
Expand Down Expand Up @@ -275,11 +277,12 @@ func (o *UnsignedCorim) Valid() error {
}
}

return o.Extensions.validCorim(o)
return o.Extensions.validCorim(&o)
}

// ToCBOR serializes the target unsigned CoRIM to CBOR
func (o *UnsignedCorim) ToCBOR() ([]byte, error) {
// nolint:gocritic
func (o UnsignedCorim) ToCBOR() ([]byte, error) {
// If extensions have been registered, the collection will exist, but
// might be empty. If that is the case, set it to nil to avoid
// marshaling an empty list (and let the marshaller omit the claim
Expand All @@ -299,7 +302,8 @@ func (o *UnsignedCorim) FromCBOR(data []byte) error {
}

// ToJSON serializes the target unsigned CoRIM to JSON
func (o *UnsignedCorim) ToJSON() ([]byte, error) {
// nolint:gocritic
func (o UnsignedCorim) ToJSON() ([]byte, error) {
// If extensions have been registered, the collection will exist, but
// might be empty. If that is the case, set it to nil to avoid
// marshaling an empty list (and let the marshaller omit the claim
Expand Down
16 changes: 10 additions & 6 deletions cots/abbreviated_swid_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,26 +158,30 @@ func NewTag(tagID interface{}, softwareName, softwareVersion string) (*Abbreviat
return &t, nil
}

func (t *AbbreviatedSwidTag) Valid() error {
if t == nil || len(t.Entities) == 0 {
// nolint:gocritic
func (t AbbreviatedSwidTag) Valid() error {
if len(t.Entities) == 0 || t.Entities == nil {
return fmt.Errorf("no entities present, must have at least 1 entity")
}
return nil
}

// ToXML serializes the receiver AbbreviatedSwidTag to SWID
func (t *AbbreviatedSwidTag) ToXML() ([]byte, error) {
// nolint:gocritic
func (t AbbreviatedSwidTag) ToXML() ([]byte, error) {
return xml.Marshal(t)
}

// ToJSON serializes the receiver AbbreviatedSwidTag to CoSWID using the JSON
// formatter
func (t *AbbreviatedSwidTag) ToJSON() ([]byte, error) {
// formatter.
// nolint:gocritic
func (t AbbreviatedSwidTag) ToJSON() ([]byte, error) {
return json.Marshal(t)
}

// ToCBOR serializes the receiver AbbreviatedSwidTag to CoSWID
func (t *AbbreviatedSwidTag) ToCBOR() ([]byte, error) {
// nolint:gocritic
func (t AbbreviatedSwidTag) ToCBOR() ([]byte, error) {
return em.Marshal(t)
}

Expand Down
19 changes: 11 additions & 8 deletions cots/cots.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,24 @@ func (o *ConciseTaStore) SetKeys(keys TasAndCas) *ConciseTaStore {
return o
}

// ToCBOR serializes the target ConciseTaStore to CBOR
func (o *ConciseTaStore) ToCBOR() ([]byte, error) {
// ToCBOR serializes the target ConciseTaStore to CBOR.
// nolint:gocritic
func (o ConciseTaStore) ToCBOR() ([]byte, error) {
if err := o.Valid(); err != nil {
return nil, err
}

return em.Marshal(o)
}

// FromCBOR deserializes a CBOR-encoded CoTS into the target ConciseTaStore
// FromCBOR deserializes a CBOR-encoded CoTS into the target ConciseTaStore.
func (o *ConciseTaStore) FromCBOR(data []byte) error {
return dm.Unmarshal(data, o)
}

// Valid iterates over the range of individual entities to check for validity
func (o *ConciseTaStore) Valid() error {
// Valid iterates over the range of individual entities to check for validity.
// nolint:gocritic
func (o ConciseTaStore) Valid() error {
if o.Environments == nil {
return fmt.Errorf("environmentGroups must be present")
}
Expand All @@ -121,13 +123,14 @@ func (o *ConciseTaStore) Valid() error {
return nil
}

// FromJSON deserializes a JSON-encoded CoTS into the target ConciseTaStore
// FromJSON deserializes a JSON-encoded CoTS into the target ConciseTaStore.
func (o *ConciseTaStore) FromJSON(data []byte) error {
return json.Unmarshal(data, o)
}

// FromJSON deserializes a JSON-encoded CoTS into the target ConsiseTaStore
func (o *ConciseTaStore) ToJSON() ([]byte, error) {
// FromJSON deserializes a JSON-encoded CoTS into the target ConsiseTaStore.
// nolint:gocritic
func (o ConciseTaStore) ToJSON() ([]byte, error) {
return json.Marshal(o)
}

Expand Down
14 changes: 8 additions & 6 deletions cots/eat_cwtclaims.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,24 @@ type EatCWTClaim struct {
SoftwareVersionScheme *HardwareVersionType `cbor:"999,keyasint,omitempty" json:"swversion,omitempty"`
}

// ToCBOR serializes the target EatCWTClaim to CBOR
func (o *EatCWTClaim) ToCBOR() ([]byte, error) {
// ToCBOR serializes the target EatCWTClaim to CBOR.
// nolint:gocritic
func (o EatCWTClaim) ToCBOR() ([]byte, error) {
return em.Marshal(o)
}

// FromCBOR deserializes a CBOR-encoded data into the target EatCWTClaim
// FromCBOR deserializes a CBOR-encoded data into the target EatCWTClaim.
func (o *EatCWTClaim) FromCBOR(data []byte) error {
return dm.Unmarshal(data, o)
}

// ToJSON serializes the target EatCWTClaim to JSON
func (o *EatCWTClaim) ToJSON() ([]byte, error) {
// ToJSON serializes the target EatCWTClaim to JSON.
// nolint:gocritic
func (o EatCWTClaim) ToJSON() ([]byte, error) {
return json.Marshal(o)
}

// FromJSON deserializes a JSON-encoded data into the target EatCWTClaim
// FromJSON deserializes a JSON-encoded data into the target EatCWTClaim.
func (o *EatCWTClaim) FromJSON(data []byte) error {
return json.Unmarshal(data, o)
}
Expand Down

0 comments on commit eef777e

Please sign in to comment.