From ae474092755a5e8337ff5628d54ccffe7d41bedc Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Fri, 24 Feb 2023 12:18:41 +0000 Subject: [PATCH] lint: remove lint-extra & fix existing issues - Remove lint-extra make target, adding the extra flags to the lint target. - Fix existing issues reported with the extra flags. Signed-off-by: Sergei Trofimov --- Makefile | 11 +++-------- claims_common.go | 4 ++-- claims_p1.go | 34 +++++++++++++++++----------------- claims_p2.go | 34 +++++++++++++++++----------------- doc.go | 1 + 5 files changed, 40 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index 2ef5867..fbd247b 100644 --- a/Makefile +++ b/Makefile @@ -8,15 +8,11 @@ GOPKG := github.com/veraison/psatoken GOLINT ?= golangci-lint ifeq ($(MAKECMDGOALS),lint) -GOLINT_ARGS ?= run --timeout=3m -else - ifeq ($(MAKECMDGOALS),lint-extra) - GOLINT_ARGS ?= run --timeout=3m --issues-exit-code=0 -E dupl -E gocritic -E gosimple -E lll -E prealloc - endif +GOLINT_ARGS ?= run --timeout=3m -E dupl -E gocritic -E gosimple -E lll -E prealloc endif -.PHONY: lint lint-extra -lint lint-extra: ; $(GOLINT) $(GOLINT_ARGS) +.PHONY: lint +lint: ; $(GOLINT) $(GOLINT_ARGS) ifeq ($(MAKECMDGOALS),test) GOTEST_ARGS ?= -v -race $(GOPKG) @@ -51,6 +47,5 @@ help: @echo " * test-cover: run unit tests and measure coverage for $(GOPKG)" @echo " * licenses: check licenses of dependent packages" @echo " * lint: lint sources using default configuration" - @echo " * lint-extra: lint sources using default configuration and some extra checkers" @echo " * presubmit: check you are ready to push your local branch to remote" @echo " * help: print this menu" diff --git a/claims_common.go b/claims_common.go index 979d2df..23490ec 100644 --- a/claims_common.go +++ b/claims_common.go @@ -240,8 +240,8 @@ func isValidSecurityLifeCycle(v uint16, profile string) error { } var ( - CertificationReferenceP1RE = regexp.MustCompile(`^[0-9]{13}$`) - CertificationReferenceP2RE = regexp.MustCompile(`^[0-9]{13}-[0-9]{5}$`) + CertificationReferenceP1RE = regexp.MustCompile(`^\d{13}$`) + CertificationReferenceP2RE = regexp.MustCompile(`^\d{13}-\d{5}$`) ) func isValidImplID(v []byte) error { diff --git a/claims_p1.go b/claims_p1.go index 6af9ca6..d3331a8 100644 --- a/claims_p1.go +++ b/claims_p1.go @@ -37,7 +37,7 @@ func newP1Claims(includeProfile bool) (IClaims, error) { } // Semantic validation -func (c P1Claims) Validate() error { +func (c P1Claims) Validate() error { //nolint:gocritic return validate(&c, PsaProfile1) } @@ -149,7 +149,7 @@ func (c *P1Claims) FromUnvalidatedCBOR(buf []byte) error { return nil } -func (c P1Claims) ToCBOR() ([]byte, error) { +func (c P1Claims) ToCBOR() ([]byte, error) { //nolint:gocritic err := c.Validate() if err != nil { return nil, fmt.Errorf("validation of PSA claims failed: %w", err) @@ -158,7 +158,7 @@ func (c P1Claims) ToCBOR() ([]byte, error) { return c.ToUnvalidatedCBOR() } -func (c P1Claims) ToUnvalidatedCBOR() ([]byte, error) { +func (c P1Claims) ToUnvalidatedCBOR() ([]byte, error) { //nolint:gocritic buf, err := em.Marshal(&c) if err != nil { return nil, fmt.Errorf("CBOR encoding of PSA claims failed: %w", err) @@ -190,7 +190,7 @@ func (c *P1Claims) FromUnvalidatedJSON(buf []byte) error { return nil } -func (c P1Claims) ToJSON() ([]byte, error) { +func (c P1Claims) ToJSON() ([]byte, error) { //nolint:gocritic err := c.Validate() if err != nil { return nil, fmt.Errorf("validation of PSA claims failed: %w", err) @@ -199,7 +199,7 @@ func (c P1Claims) ToJSON() ([]byte, error) { return c.ToUnvalidatedJSON() } -func (c P1Claims) ToUnvalidatedJSON() ([]byte, error) { +func (c P1Claims) ToUnvalidatedJSON() ([]byte, error) { //nolint:gocritic buf, err := json.Marshal(&c) if err != nil { return nil, fmt.Errorf("JSON encoding of PSA claims failed: %w", err) @@ -213,7 +213,7 @@ func (c P1Claims) ToUnvalidatedJSON() ([]byte, error) { // to never fail. Getters of optional claim may still fail with // ErrOptionalClaimMissing in case the claim is not present. -func (c P1Claims) GetProfile() (string, error) { +func (c P1Claims) GetProfile() (string, error) { //nolint:gocritic if c.Profile == nil { return PsaProfile1, nil } @@ -221,28 +221,28 @@ func (c P1Claims) GetProfile() (string, error) { return *c.Profile, nil } -func (c P1Claims) GetClientID() (int32, error) { +func (c P1Claims) GetClientID() (int32, error) { //nolint:gocritic return getClientID(c.ClientID) } -func (c P1Claims) GetSecurityLifeCycle() (uint16, error) { +func (c P1Claims) GetSecurityLifeCycle() (uint16, error) { //nolint:gocritic return getSecurityLifeCycle(c.SecurityLifeCycle, PsaProfile1) } -func (c P1Claims) GetImplID() ([]byte, error) { +func (c P1Claims) GetImplID() ([]byte, error) { //nolint:gocritic return getImplID(c.ImplID) } -func (c P1Claims) GetBootSeed() ([]byte, error) { +func (c P1Claims) GetBootSeed() ([]byte, error) { //nolint:gocritic return getBootSeed(c.BootSeed, PsaProfile1) } -func (c P1Claims) GetCertificationReference() (string, error) { +func (c P1Claims) GetCertificationReference() (string, error) { //nolint:gocritic return getCertificationReference(c.CertificationReference, PsaProfile1) } // Caveat: this may return nil on success if psa-no-sw-measurement is asserted -func (c P1Claims) GetSoftwareComponents() ([]SwComponent, error) { +func (c P1Claims) GetSoftwareComponents() ([]SwComponent, error) { //nolint:gocritic v := c.SwComponents f := c.NoSwMeasurements @@ -270,7 +270,7 @@ func (c P1Claims) GetSoftwareComponents() ([]SwComponent, error) { return *v, nil } -func (c P1Claims) GetNonce() ([]byte, error) { +func (c P1Claims) GetNonce() ([]byte, error) { //nolint:gocritic v := c.Nonce if v == nil { @@ -284,7 +284,7 @@ func (c P1Claims) GetNonce() ([]byte, error) { return *v, nil } -func (c P1Claims) GetInstID() ([]byte, error) { +func (c P1Claims) GetInstID() ([]byte, error) { //nolint:gocritic v := c.InstID if v == nil { @@ -298,16 +298,16 @@ func (c P1Claims) GetInstID() ([]byte, error) { return *v, nil } -func (c P1Claims) GetVSI() (string, error) { +func (c P1Claims) GetVSI() (string, error) { //nolint:gocritic return getVSI(c.VSI) } -func (c P1Claims) GetConfig() ([]byte, error) { +func (c P1Claims) GetConfig() ([]byte, error) { //nolint:gocritic return nil, fmt.Errorf("invalid GetConfig invoked on p1 claims") } -func (c P1Claims) GetHashAlgID() (string, error) { +func (c P1Claims) GetHashAlgID() (string, error) { //nolint:gocritic return "", fmt.Errorf("invalid GetHashAlgID invoked on p1 claims") } diff --git a/claims_p2.go b/claims_p2.go index 7feb2f6..58e708d 100644 --- a/claims_p2.go +++ b/claims_p2.go @@ -36,7 +36,7 @@ func newP2Claims() (IClaims, error) { } // Semantic validation -func (c P2Claims) Validate() error { +func (c P2Claims) Validate() error { //nolint:gocritic return validate(&c, PsaProfile2) } @@ -151,7 +151,7 @@ func (c *P2Claims) FromUnvalidatedCBOR(buf []byte) error { return nil } -func (c P2Claims) ToCBOR() ([]byte, error) { +func (c P2Claims) ToCBOR() ([]byte, error) { //nolint:gocritic err := c.Validate() if err != nil { return nil, fmt.Errorf("validation of PSA claims failed: %w", err) @@ -160,7 +160,7 @@ func (c P2Claims) ToCBOR() ([]byte, error) { return c.ToUnvalidatedCBOR() } -func (c P2Claims) ToUnvalidatedCBOR() ([]byte, error) { +func (c P2Claims) ToUnvalidatedCBOR() ([]byte, error) { //nolint:gocritic buf, err := em.Marshal(&c) if err != nil { return nil, fmt.Errorf("CBOR encoding of PSA claims failed: %w", err) @@ -192,7 +192,7 @@ func (c *P2Claims) FromUnvalidatedJSON(buf []byte) error { return nil } -func (c P2Claims) ToJSON() ([]byte, error) { +func (c P2Claims) ToJSON() ([]byte, error) { //nolint:gocritic err := c.Validate() if err != nil { return nil, fmt.Errorf("validation of PSA claims failed: %w", err) @@ -201,7 +201,7 @@ func (c P2Claims) ToJSON() ([]byte, error) { return c.ToUnvalidatedJSON() } -func (c P2Claims) ToUnvalidatedJSON() ([]byte, error) { +func (c P2Claims) ToUnvalidatedJSON() ([]byte, error) { //nolint:gocritic buf, err := json.Marshal(&c) if err != nil { return nil, fmt.Errorf("JSON encoding of PSA claims failed: %w", err) @@ -215,7 +215,7 @@ func (c P2Claims) ToUnvalidatedJSON() ([]byte, error) { // to never fail. Getters of optional claim may still fail with // ErrOptionalClaimMissing in case the claim is not present. -func (c P2Claims) GetProfile() (string, error) { +func (c P2Claims) GetProfile() (string, error) { //nolint:gocritic if c.Profile == nil { return "", ErrMandatoryClaimMissing } @@ -223,27 +223,27 @@ func (c P2Claims) GetProfile() (string, error) { return c.Profile.Get() } -func (c P2Claims) GetClientID() (int32, error) { +func (c P2Claims) GetClientID() (int32, error) { //nolint:gocritic return getClientID(c.ClientID) } -func (c P2Claims) GetSecurityLifeCycle() (uint16, error) { +func (c P2Claims) GetSecurityLifeCycle() (uint16, error) { //nolint:gocritic return getSecurityLifeCycle(c.SecurityLifeCycle, PsaProfile2) } -func (c P2Claims) GetImplID() ([]byte, error) { +func (c P2Claims) GetImplID() ([]byte, error) { //nolint:gocritic return getImplID(c.ImplID) } -func (c P2Claims) GetBootSeed() ([]byte, error) { +func (c P2Claims) GetBootSeed() ([]byte, error) { //nolint:gocritic return getBootSeed(c.BootSeed, PsaProfile2) } -func (c P2Claims) GetCertificationReference() (string, error) { +func (c P2Claims) GetCertificationReference() (string, error) { //nolint:gocritic return getCertificationReference(c.CertificationReference, PsaProfile2) } -func (c P2Claims) GetSoftwareComponents() ([]SwComponent, error) { +func (c P2Claims) GetSoftwareComponents() ([]SwComponent, error) { //nolint:gocritic v := c.SwComponents if v == nil { @@ -257,7 +257,7 @@ func (c P2Claims) GetSoftwareComponents() ([]SwComponent, error) { return *v, nil } -func (c P2Claims) GetNonce() ([]byte, error) { +func (c P2Claims) GetNonce() ([]byte, error) { //nolint:gocritic v := c.Nonce if v == nil { @@ -278,7 +278,7 @@ func (c P2Claims) GetNonce() ([]byte, error) { return n, nil } -func (c P2Claims) GetInstID() ([]byte, error) { +func (c P2Claims) GetInstID() ([]byte, error) { //nolint:gocritic v := c.InstID if v == nil { @@ -292,14 +292,14 @@ func (c P2Claims) GetInstID() ([]byte, error) { return *v, nil } -func (c P2Claims) GetVSI() (string, error) { +func (c P2Claims) GetVSI() (string, error) { //nolint:gocritic return getVSI(c.VSI) } -func (c P2Claims) GetConfig() ([]byte, error) { +func (c P2Claims) GetConfig() ([]byte, error) { //nolint:gocritic return nil, fmt.Errorf("invalid GetConfig invoked on p2 claims") } -func (c P2Claims) GetHashAlgID() (string, error) { +func (c P2Claims) GetHashAlgID() (string, error) { //nolint:gocritic return "", fmt.Errorf("invalid GetHashAlgID invoked on p2 claims") } diff --git a/doc.go b/doc.go index 2902b16..e740f92 100644 --- a/doc.go +++ b/doc.go @@ -75,4 +75,5 @@ processed, e.g.: myPolicy.VerifyAttestation(evidence.Claims) */ +//nolint:gofmt package psatoken