From eef777e135a3fe276e5bdeb64c625b05e30d39ba Mon Sep 17 00:00:00 2001 From: "Akhilesh Kr. Yadav" Date: Wed, 15 Jan 2025 19:08:02 +0530 Subject: [PATCH] merging-extra-lint Signed-off-by: Akhilesh Kr. Yadav --- comid/comid.go | 20 ++++++++++++-------- comid/flagsmap.go | 15 ++++++++++----- comid/measurement.go | 17 +++++++++++------ corim/unsignedcorim.go | 14 +++++++++----- cots/abbreviated_swid_tag.go | 16 ++++++++++------ cots/cots.go | 19 +++++++++++-------- cots/eat_cwtclaims.go | 14 ++++++++------ 7 files changed, 71 insertions(+), 44 deletions(-) diff --git a/comid/comid.go b/comid/comid.go index ab02de5..51ca1fe 100644 --- a/comid/comid.go +++ b/comid/comid.go @@ -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) } @@ -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 } @@ -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 @@ -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 } @@ -306,7 +309,7 @@ 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 @@ -314,10 +317,11 @@ 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) } diff --git a/comid/flagsmap.go b/comid/flagsmap.go index d6c42cb..5a68233 100644 --- a/comid/flagsmap.go +++ b/comid/flagsmap.go @@ -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 { @@ -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) } @@ -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) } diff --git a/comid/measurement.go b/comid/measurement.go index 72feb40..e716269 100644 --- a/comid/measurement.go +++ b/comid/measurement.go @@ -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 @@ -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 @@ -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 && @@ -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. @@ -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() } @@ -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 diff --git a/corim/unsignedcorim.go b/corim/unsignedcorim.go index 7a05174..9f34add 100644 --- a/corim/unsignedcorim.go +++ b/corim/unsignedcorim.go @@ -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() } @@ -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") } @@ -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 @@ -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 diff --git a/cots/abbreviated_swid_tag.go b/cots/abbreviated_swid_tag.go index 1d2fd52..7cc64e0 100644 --- a/cots/abbreviated_swid_tag.go +++ b/cots/abbreviated_swid_tag.go @@ -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) } diff --git a/cots/cots.go b/cots/cots.go index 40831f1..bec6765 100644 --- a/cots/cots.go +++ b/cots/cots.go @@ -83,8 +83,9 @@ 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 } @@ -92,13 +93,14 @@ func (o *ConciseTaStore) ToCBOR() ([]byte, error) { 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") } @@ -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) } diff --git a/cots/eat_cwtclaims.go b/cots/eat_cwtclaims.go index 18231a1..8865161 100644 --- a/cots/eat_cwtclaims.go +++ b/cots/eat_cwtclaims.go @@ -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) }