Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some golangci-lint warnings #144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion comid/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func Test_NewBytesInstance_OK(t *testing.T) {
instance, err := NewBytesInstance(v)
require.NoError(t, err)
got := instance.Bytes()
assert.Equal(t, testBytes[:], got)
assert.Equal(t, testBytes, got)
}
}

Expand Down
10 changes: 5 additions & 5 deletions cots/cas_and_tas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestTrustAnchor_JSON_Roundtrip(t *testing.T) {
err := tv2.FromJSON(j)
assert.Nil(t, err)

assert.True(t, len(tv2.Data) == len(ta) && 0 == bytes.Compare(ta, tv2.Data), "Compare TA value")
assert.True(t, len(tv2.Data) == len(ta) && bytes.Equal(ta, tv2.Data), "Compare TA value")
assert.True(t, TaFormatCertificate == tv2.Format, "Compare TA format")

}
Expand All @@ -166,7 +166,7 @@ func TestTrustAnchor_CBOR_Roundtrip(t *testing.T) {
err := tv2.FromCBOR(c)
assert.Nil(t, err)

assert.True(t, len(tv2.Data) == len(ta) && 0 == bytes.Compare(ta, tv2.Data), "Compare TA value")
assert.True(t, len(tv2.Data) == len(ta) && bytes.Equal(ta, tv2.Data), "Compare TA value")
assert.True(t, TaFormatCertificate == tv2.Format, "Compare TA format")

}
Expand Down Expand Up @@ -203,9 +203,9 @@ func TestTasAndCas_JSON_full_Roundtrip(t *testing.T) {
err := tv2.FromJSON(j)
assert.Nil(t, err)

assert.True(t, len(tv2.Tas[0].Data) == len(ta) && 0 == bytes.Compare(ta, tv2.Tas[0].Data), "Compare TA value")
assert.True(t, len(tv2.Tas[0].Data) == len(ta) && bytes.Equal(ta, tv2.Tas[0].Data), "Compare TA value")
assert.True(t, TaFormatCertificate == tv2.Tas[0].Format, "Compare TA format")
assert.True(t, len(tv2.Cas[0]) == len(ca) && 0 == bytes.Compare(ca, tv2.Cas[0]), "Compare CA")
assert.True(t, len(tv2.Cas[0]) == len(ca) && bytes.Equal(ca, tv2.Cas[0]), "Compare CA")
}

func TestTasAndCas_CBOR_full_Roundtrip(t *testing.T) {
Expand All @@ -221,7 +221,7 @@ func TestTasAndCas_CBOR_full_Roundtrip(t *testing.T) {
err := tv2.FromCBOR(c)
assert.Nil(t, err)

assert.True(t, len(tv2.Tas[0].Data) == len(ta) && 0 == bytes.Compare(ta, tv2.Tas[0].Data), "Compare TA value")
assert.True(t, len(tv2.Tas[0].Data) == len(ta) && bytes.Equal(ta, tv2.Tas[0].Data), "Compare TA value")
assert.True(t, TaFormatCertificate == tv2.Tas[0].Format, "Compare TA format")
assert.True(t, TaFormatCertificate == tv2.Tas[0].Format, "Compare TA format")
}
2 changes: 1 addition & 1 deletion cots/cots.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
o.TagIdentity = &comid.TagIdentity{}
o.TagIdentity.TagID = *id
if nil != tagIDVersion {
if tagIDVersion != nil {
o.TagIdentity.TagVersion = *tagIDVersion
}
}
Expand Down Expand Up @@ -62,14 +62,14 @@
return o
}

func (o *ConciseTaStore) AddPermClaims(permclaim EatCWTClaim) *ConciseTaStore {

Check failure on line 65 in cots/cots.go

View workflow job for this annotation

GitHub Actions / Lint

hugeParam: permclaim is heavy (176 bytes); consider passing it by pointer (gocritic)
if o != nil {
o.PermClaims = append(o.PermClaims, permclaim)
}
return o
}

func (o *ConciseTaStore) AddExclClaims(exclclaim EatCWTClaim) *ConciseTaStore {

Check failure on line 72 in cots/cots.go

View workflow job for this annotation

GitHub Actions / Lint

hugeParam: exclclaim is heavy (176 bytes); consider passing it by pointer (gocritic)
if o != nil {
o.ExclClaims = append(o.ExclClaims, exclclaim)
}
Expand All @@ -84,7 +84,7 @@
}

// ToCBOR serializes the target ConciseTaStore to CBOR
func (o ConciseTaStore) ToCBOR() ([]byte, error) {

Check failure on line 87 in cots/cots.go

View workflow job for this annotation

GitHub Actions / Lint

hugeParam: o is heavy (120 bytes); consider passing it by pointer (gocritic)
if err := o.Valid(); err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions cots/eat_cwtclaims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func getNonce() eat.Nonce {
return nonce
}

func cborRoundTripper(t *testing.T, tv EatCWTClaim, expected []byte) {
func cborRoundTripper(t *testing.T, tv *EatCWTClaim, expected []byte) {
data, err := tv.ToCBOR()

t.Logf("CBOR: %x", data)
Expand All @@ -79,10 +79,10 @@ func cborRoundTripper(t *testing.T, tv EatCWTClaim, expected []byte) {
err = actual.FromCBOR(data)

assert.Nil(t, err)
assert.Equal(t, tv, actual)
assert.Equal(t, *tv, actual)
}

func jsonRoundTripper(t *testing.T, tv EatCWTClaim, expected string) {
func jsonRoundTripper(t *testing.T, tv *EatCWTClaim, expected string) {
data, err := tv.ToJSON()

t.Logf("JSON: '%s'", string(data))
Expand All @@ -94,7 +94,7 @@ func jsonRoundTripper(t *testing.T, tv EatCWTClaim, expected string) {
err = actual.FromJSON(data)

assert.Nil(t, err)
assert.Equal(t, tv, actual)
assert.Equal(t, *tv, actual)
}

func TestEatCWTClaim_Full_RoundtripCBOR(t *testing.T) {
Expand All @@ -116,7 +116,7 @@ func TestEatCWTClaim_Full_RoundtripCBOR(t *testing.T) {
0xff, 0xff, 0xff, 0xff, 0xff,
}

cborRoundTripper(t, tv, expected)
cborRoundTripper(t, &tv, expected)
}

func TestEatCWTClaim_Full_RoundtripJSON(t *testing.T) {
Expand All @@ -143,7 +143,7 @@ func TestEatCWTClaim_Full_RoundtripJSON(t *testing.T) {
"iat": 0,
"cti": "////////"
}`
jsonRoundTripper(t, tv, expected)
jsonRoundTripper(t, &tv, expected)
}

func TestEatCWTClaims_Valid_empty_list(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions encoding/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ func (o *structFieldsCBOR) ToCBOR(em cbor.EncMode) ([]byte, error) {
header |= byte(25)
out = append(out, header)
out = binary.BigEndian.AppendUint16(out, uint16(mapLen))
} else {
} else if mapLen <= math.MaxUint32 {
header |= byte(26)
out = append(out, header)
out = binary.BigEndian.AppendUint32(out, uint32(mapLen))
} else {
return nil, errors.New("mapLen cannot exceed math.MaxUint32")
}
// Since len() returns an int, the value cannot exceed MaxUint32, so
// the 8-byte length variant cannot occur.

for _, key := range o.Keys {
marshalledKey, err := em.Marshal(key)
Expand Down
Loading