Skip to content

Commit 75b1451

Browse files
committed
chore: fix linter errors
1 parent 50cbac6 commit 75b1451

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ type onionBlindingJsonTestCase struct {
521521
Decrypt decryptData `json:"decrypt"`
522522
}
523523

524+
//nolint:tagliatelle
524525
type generateOnionData struct {
525526
SessionKey string `json:"session_key"`
526527
AssocData string `json:"associated_data"`
@@ -535,8 +536,8 @@ type decryptOnionMessageData struct {
535536
Hops []decryptOnionMessageHops `json:"hops"`
536537
}
537538

538-
type decryptHops struct {
539539
//nolint:tagliatelle
540+
type decryptHops struct {
540541
Onion string `json:"onion"`
541542
NodePrivKey string `json:"node_privkey"`
542543
NextBlinding string `json:"next_blinding"`
@@ -562,8 +563,8 @@ type onionMessageJsonTestCase struct {
562563
Decrypt decryptOnionMessageData `json:"decrypt"`
563564
}
564565

565-
type routeData struct {
566566
//nolint:tagliatelle
567+
type routeData struct {
567568
IntroductionNodeID string `json:"introduction_node_id"`
568569
Blinding string `json:"blinding"`
569570
Hops []blindedHop `json:"hops"`
@@ -595,14 +596,15 @@ type generateOnionMessageData struct {
595596
Hops []hopOnionMessageData `json:"hops"`
596597
}
597598

599+
//nolint:tagliatelle
598600
type unblindedHop struct {
599601
NodePrivKey string `json:"node_privkey"`
600-
//nolint:tagliatelle
601602
EphemeralPubKey string `json:"ephemeral_pubkey"`
602603
DecryptedData string `json:"decrypted_data"`
603604
NextEphemeralPubKey string `json:"next_ephemeral_pubkey"`
604605
}
605606

607+
//nolint:tagliatelle
606608
type hopData struct {
607609
SessionKey string `json:"session_key"`
608610
NodeID string `json:"node_id"`

sphinx.go

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

231231
totalPayloadSize := paymentPath.TotalPayloadSize()
@@ -402,11 +402,13 @@ func generateHeaderPadding(key string, path *PaymentPath,
402402
func (f *OnionPacket) Encode(w io.Writer) error {
403403
ephemeral := f.EphemeralKey.SerializeCompressed()
404404

405-
if _, err := w.Write([]byte{f.Version}); err != nil {
405+
_, err := w.Write([]byte{f.Version})
406+
if err != nil {
406407
return err
407408
}
408409

409-
if _, err := w.Write(ephemeral); err != nil {
410+
_, err = w.Write(ephemeral)
411+
if err != nil {
410412
return err
411413
}
412414

@@ -415,7 +417,8 @@ func (f *OnionPacket) Encode(w io.Writer) error {
415417
return err
416418
}
417419

418-
if _, err := w.Write(f.HeaderMAC[:]); err != nil {
420+
_, err = w.Write(f.HeaderMAC[:])
421+
if err != nil {
419422
return err
420423
}
421424

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)