Skip to content

Commit 60d3d80

Browse files
committed
chore: fix linter errors
1 parent 1ef0307 commit 60d3d80

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ linters:
5252
# Checks the number of statements in a function.
5353
statements: 50
5454

55+
tagliatelle:
56+
case:
57+
rules:
58+
json: snake
59+
5560
wsl_v5:
5661
# We adopt a more relaxed cuddling rule by enabling
5762
# `allow-whole-block`. This allows a variable declaration to be

error.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
package sphinx
22

3-
import (
4-
"errors"
5-
"fmt"
6-
)
3+
import "errors"
74

85
var (
96
// ErrReplayedPacket is an error returned when a packet is rejected
107
// during processing due to being an attempted replay or probing
118
// attempt.
12-
ErrReplayedPacket = fmt.Errorf("sphinx packet replay attempted")
9+
ErrReplayedPacket = errors.New("sphinx packet replay attempted")
1310

1411
// ErrInvalidOnionVersion is returned during decoding of the onion
1512
// packet, when the received packet has an unknown version byte.
16-
ErrInvalidOnionVersion = fmt.Errorf("invalid onion packet version")
13+
ErrInvalidOnionVersion = errors.New("invalid onion packet version")
1714

18-
// ErrInvalidOnionHMAC is returned during onion parsing process, when received
19-
// mac does not corresponds to the generated one.
20-
ErrInvalidOnionHMAC = fmt.Errorf("invalid mismatched mac")
15+
// ErrInvalidOnionHMAC is returned during onion parsing process, when
16+
// received mac does not corresponds to the generated one.
17+
ErrInvalidOnionHMAC = errors.New("invalid mismatched mac")
2118

2219
// ErrInvalidOnionKey is returned during onion parsing process, when
2320
// onion key is invalid.
24-
ErrInvalidOnionKey = fmt.Errorf("invalid onion key: pubkey isn't on " +
21+
ErrInvalidOnionKey = errors.New("invalid onion key: pubkey isn't on " +
2522
"secp256k1 curve")
2623

2724
// ErrLogEntryNotFound is an error returned when a packet lookup in a

path_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,6 @@ type decryptOnionMessageData struct {
537537
}
538538

539539
type decryptHops struct {
540-
//nolint:tagliatelle
541540
Onion string `json:"onion"`
542541
NodePrivKey string `json:"node_privkey"`
543542
NextBlinding string `json:"next_blinding"`
@@ -592,8 +591,7 @@ type generateOnionMessageData struct {
592591
}
593592

594593
type unblindedHop struct {
595-
NodePrivKey string `json:"node_privkey"`
596-
//nolint:tagliatelle
594+
NodePrivKey string `json:"node_privkey"`
597595
EphemeralPubKey string `json:"ephemeral_pubkey"`
598596
DecryptedData string `json:"decrypted_data"`
599597
NextEphemeralPubKey string `json:"next_ephemeral_pubkey"`

sphinx.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func NewOnionPacket(paymentPath *PaymentPath, sessionKey *btcec.PrivateKey,
228228
// exit early.
229229
numHops := paymentPath.TrueRouteLength()
230230
if numHops == 0 {
231-
return nil, fmt.Errorf("route of length zero passed in")
231+
return nil, ErrZeroHops
232232
}
233233

234234
totalPayloadSize := paymentPath.TotalPayloadSize()
@@ -407,20 +407,23 @@ func generateHeaderPadding(key string, path *PaymentPath,
407407
func (f *OnionPacket) Encode(w io.Writer) error {
408408
ephemeral := f.EphemeralKey.SerializeCompressed()
409409

410-
if _, err := w.Write([]byte{f.Version}); err != nil {
410+
_, err := w.Write([]byte{f.Version})
411+
if err != nil {
411412
return err
412413
}
413414

414-
if _, err := w.Write(ephemeral); err != nil {
415+
_, err = w.Write(ephemeral)
416+
if err != nil {
415417
return err
416418
}
417419

418-
_, err := w.Write(f.RoutingInfo)
420+
_, err = w.Write(f.RoutingInfo)
419421
if err != nil {
420422
return err
421423
}
422424

423-
if _, err := w.Write(f.HeaderMAC[:]); err != nil {
425+
_, err = w.Write(f.HeaderMAC[:])
426+
if err != nil {
424427
return err
425428
}
426429

sphinx_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,7 @@ func newTestRoute(numHops int) ([]*Router, *PaymentPath, *[]HopData, *OnionPacke
9898

9999
// Create numHops random sphinx nodes.
100100
for i := 0; i < len(nodes); i++ {
101-
privKey, err := btcec.NewPrivateKey()
102-
if err != nil {
103-
return nil, nil, nil, nil, fmt.Errorf("Unable to "+
104-
"generate random key for sphinx node: %v", err)
105-
}
106-
101+
privKey, _ := btcec.NewPrivateKey()
107102
nodes[i] = NewRouter(
108103
&PrivKeyECDH{PrivKey: privKey}, NewMemoryReplayLog(),
109104
)

0 commit comments

Comments
 (0)