Skip to content

Commit

Permalink
lint: remove lint-extra & fix existing issues
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
setrofim committed Mar 30, 2023
1 parent 8aa6a7e commit ae47409
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 44 deletions.
11 changes: 3 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
4 changes: 2 additions & 2 deletions claims_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 17 additions & 17 deletions claims_p1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -213,36 +213,36 @@ 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
}

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

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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")
}
34 changes: 17 additions & 17 deletions claims_p2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -215,35 +215,35 @@ 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
}

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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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")
}
1 change: 1 addition & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ processed, e.g.:
myPolicy.VerifyAttestation(evidence.Claims)
*/
//nolint:gofmt
package psatoken

0 comments on commit ae47409

Please sign in to comment.