Skip to content

Commit

Permalink
fix: Linter warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
  • Loading branch information
stv0g committed Nov 29, 2024
1 parent 795e4ef commit 963a4aa
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ linters:
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
- exhaustive # check exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- copyloopvar
- forcetypeassert # finds forced type assertions
- gci # Gci control golang package import order and make it always deterministic.
- gochecknoglobals # Checks that no globals are present in Go code
Expand Down Expand Up @@ -98,7 +98,6 @@ linters:
- gocyclo # Computes and checks the cyclomatic complexity of functions
- godot # Check if comments end in a period
- godox # Tool for detection of FIXME, TODO and other comment keywords
- gomnd # An analyzer to detect magic numbers.
- ireturn # Accept Interfaces, Return Concrete Types
- lll # Reports long lines
- maintidx # maintidx measures the maintainability index of each function.
Expand Down
2 changes: 2 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2023-2024 Steffen Vogel <post@steffenvogel.de>
// SPDX-License-Identifier: Apache-2.0

//go:build darwin

package main

import (
Expand Down
10 changes: 6 additions & 4 deletions ecdh/public_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var _ dh.PublicKey = (*PublicKey)(nil)
var (
ErrUnsupportedCurve = errors.New("unsupported curve")
ErrUnmarshal = errors.New("failed to unmarshal key")
ErrParse = errors.New("failed to parse")
)

type PublicKey struct {
Expand All @@ -39,19 +40,19 @@ func (pk *PublicKey) UnmarshalText(text []byte) error {
var curveName, keyStr string

if n, err := fmt.Sscanf(string(text), "ecdh:%s:pk:%s", &curveName, &keyStr); err != nil {
return fmt.Errorf("failed to parse: %w", err)
return fmt.Errorf("%w: %w", ErrParse, err)
} else if n != 1 {
return fmt.Errorf("failed to parse")
return ErrParse
}

curve := curveFromName(curveName)
if curve == nil {
return fmt.Errorf("unsupported curve: %s", curveName)
return fmt.Errorf("%w: %s", ErrUnsupportedCurve, curveName)
}

key, err := base64.StdEncoding.DecodeString(keyStr)
if err != nil {
return fmt.Errorf("failed to parse: %w", err)
return fmt.Errorf("%w: %w", ErrParse, err)
}

pk.PublicKey, err = curve.NewPublicKey(key)
Expand Down Expand Up @@ -81,6 +82,7 @@ func (pk *PublicKey) ECDSA() (*ecdsa.PublicKey, error) {
return nil, fmt.Errorf("%w: %v", ErrUnsupportedCurve, pk.Curve())
}

//nolint:staticcheck
x, y := elliptic.Unmarshal(curve, pk.Bytes())
if x == nil {
return nil, ErrUnmarshal
Expand Down
3 changes: 0 additions & 3 deletions handshake/handshake_chained.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ func (cp ChainedHandshake) Secret(ctx context.Context) (s Secret, err error) {
res := make([]Secret, len(cp))

for i, p := range cp {
i := i
p := p

group.Go(func() (err error) {
res[i], err = p.Secret(ctx)
return err
Expand Down
2 changes: 2 additions & 0 deletions handshake/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func (k *Key) UnmarshalText(t []byte) (err error) {
parts := strings.Split(s, "_")

var protoParts int

//nolint:goconst
switch parts[0] {
case "Noise", "WireGuard":
protoParts = 5
Expand Down
1 change: 1 addition & 0 deletions internal/openpgp/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ type ApplicationRelated struct {
Keys [4]KeyInfo
}

//nolint:gocognit
func (ar *ApplicationRelated) Decode(b []byte) (err error) {
var v, w, x []byte
var t iso.Tag
Expand Down
2 changes: 2 additions & 0 deletions provider/applese.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2023-2024 Steffen Vogel <post@steffenvogel.de>
// SPDX-License-Identifier: Apache-2.0

//go:build darwin

package provider

import (
Expand Down
2 changes: 2 additions & 0 deletions provider/applese_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2023 Steffen Vogel
// SPDX-License-Identifier: Apache-2.0

//go:build darwin

package provider

import (
Expand Down
1 change: 1 addition & 0 deletions provider/openpgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (s *openpgpSlotRef) UnmarshalText(text []byte) error {
return ErrParse
}

//nolint:goconst
switch curve {
case "Secp256r1":
default:
Expand Down

0 comments on commit 963a4aa

Please sign in to comment.