From 4c24e4692bf6878a8bf4ad889680e46662315235 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 20 Nov 2022 09:13:11 +0100 Subject: [PATCH] Fix golangci-lint warnings --- cmd/clientsim/main.go | 11 ++++++----- pkg/messages/resolver.msgpackgen.go | 1 + pkg/x509/helper/helper.go | 19 ++++++++++++++++++- pkg/x509/helper/helper_test.go | 20 +++++++++++++++++++- pkg/x509/revoking/revoking_test.go | 3 ++- pkg/x509/signing/signing_test.go | 3 ++- 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/cmd/clientsim/main.go b/cmd/clientsim/main.go index c546b9b..06c3f98 100644 --- a/cmd/clientsim/main.go +++ b/cmd/clientsim/main.go @@ -27,9 +27,10 @@ import ( "sync" "time" - "git.cacert.org/cacert-gosigner/pkg/messages" "github.com/justincpresley/go-cobs" "github.com/shamaton/msgpackgen/msgpack" + + "git.cacert.org/cacert-gosigner/pkg/messages" ) const cobsDelimiter = 0x00 @@ -94,7 +95,7 @@ func (c *clientSimulator) handleInput(ctx context.Context) error { default: count, err := os.Stdin.Read(buf) if err != nil { - return err + return fmt.Errorf("reading input failed: %w", err) } if count == 0 { @@ -107,7 +108,7 @@ func (c *clientSimulator) handleInput(ctx context.Context) error { err = cobs.Verify(data, cobsConfig) if err != nil { - return err + return fmt.Errorf("frame verification failed: %w", err) } c.responses <- cobs.Decode(data, cobsConfig) @@ -157,7 +158,7 @@ func (c *clientSimulator) Run() error { var inputError, commandError error go func(inputErr error) { - inputError = c.handleInput(ctx) + _ = c.handleInput(ctx) cancel() @@ -165,7 +166,7 @@ func (c *clientSimulator) Run() error { }(inputError) go func(commandErr error) { - commandErr = c.handleCommands(ctx) + _ = c.handleCommands(ctx) cancel() diff --git a/pkg/messages/resolver.msgpackgen.go b/pkg/messages/resolver.msgpackgen.go index a999ce5..00240d5 100644 --- a/pkg/messages/resolver.msgpackgen.go +++ b/pkg/messages/resolver.msgpackgen.go @@ -4,6 +4,7 @@ package messages import ( "fmt" + msgpack "github.com/shamaton/msgpackgen/msgpack" dec "github.com/shamaton/msgpackgen/msgpack/dec" enc "github.com/shamaton/msgpackgen/msgpack/enc" diff --git a/pkg/x509/helper/helper.go b/pkg/x509/helper/helper.go index ace3a68..2578b2a 100644 --- a/pkg/x509/helper/helper.go +++ b/pkg/x509/helper/helper.go @@ -1,3 +1,20 @@ +/* +Copyright 2022 CAcert Inc. +SPDX-License-Identifier: Apache-2.0 + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package helper import ( @@ -9,7 +26,7 @@ import ( // GenerateRandomSerial generates a random serial number to be used in X.509 certificates. The implementation is // compliant to https://www.rfc-editor.org/rfc/rfc5280#section-4.1.2.2. func GenerateRandomSerial() (*big.Int, error) { - serial, err := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 160)) + serial, err := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 160)) //nolint:gomnd if err != nil { return nil, fmt.Errorf("could not generate random serial number: %w", err) } diff --git a/pkg/x509/helper/helper_test.go b/pkg/x509/helper/helper_test.go index 662a8f3..2d5bcd0 100644 --- a/pkg/x509/helper/helper_test.go +++ b/pkg/x509/helper/helper_test.go @@ -1,10 +1,28 @@ +/* +Copyright 2022 CAcert Inc. +SPDX-License-Identifier: Apache-2.0 + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package helper_test import ( "testing" - "git.cacert.org/cacert-gosigner/pkg/x509/helper" "github.com/stretchr/testify/assert" + + "git.cacert.org/cacert-gosigner/pkg/x509/helper" ) func TestGenerateRandomSerial(t *testing.T) { diff --git a/pkg/x509/revoking/revoking_test.go b/pkg/x509/revoking/revoking_test.go index bb8d934..8c05213 100644 --- a/pkg/x509/revoking/revoking_test.go +++ b/pkg/x509/revoking/revoking_test.go @@ -28,10 +28,11 @@ import ( "math/big" "testing" - "git.cacert.org/cacert-gosigner/pkg/x509/helper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "git.cacert.org/cacert-gosigner/pkg/x509/helper" + "git.cacert.org/cacert-gosigner/pkg/x509/revoking" ) diff --git a/pkg/x509/signing/signing_test.go b/pkg/x509/signing/signing_test.go index 3fd186a..6435afb 100644 --- a/pkg/x509/signing/signing_test.go +++ b/pkg/x509/signing/signing_test.go @@ -28,9 +28,10 @@ import ( "testing" "time" - "git.cacert.org/cacert-gosigner/pkg/x509/helper" "github.com/stretchr/testify/assert" + "git.cacert.org/cacert-gosigner/pkg/x509/helper" + "git.cacert.org/cacert-gosigner/pkg/x509/signing" )