Skip to content

Commit 6bb979f

Browse files
committed
chore: fix linter errors
1 parent 4beb08c commit 6bb979f

File tree

5 files changed

+22
-33
lines changed

5 files changed

+22
-33
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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,11 @@ 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"`
544543
}
545544

546-
//nolint:tagliatelle
547545
type decryptOnionMessageHops struct {
548546
OnionMessage string `json:"onion_message"`
549547
PrivKey string `json:"privkey"`
@@ -564,20 +562,17 @@ type onionMessageJsonTestCase struct {
564562
}
565563

566564
type routeData struct {
567-
//nolint:tagliatelle
568565
IntroductionNodeID string `json:"introduction_node_id"`
569566
Blinding string `json:"blinding"`
570567
Hops []blindedHop `json:"hops"`
571568
}
572569

573-
//nolint:tagliatelle
574570
type routeOnionMessageData struct {
575571
FirstNodeId string `json:"first_node_id"`
576572
FirstPathKey string `json:"first_path_key"`
577573
Hops []blindedOnionMessageHop `json:"hops"`
578574
}
579575

580-
//nolint:tagliatelle
581576
type onionMessageData struct {
582577
OnionMessagePacket string `json:"onion_message_packet"`
583578
}
@@ -590,15 +585,13 @@ type generateData struct {
590585
Hops []hopData `json:"hops"`
591586
}
592587

593-
//nolint:tagliatelle
594588
type generateOnionMessageData struct {
595589
SessionKey string `json:"session_key"`
596590
Hops []hopOnionMessageData `json:"hops"`
597591
}
598592

599593
type unblindedHop struct {
600594
NodePrivKey string `json:"node_privkey"`
601-
//nolint:tagliatelle
602595
EphemeralPubKey string `json:"ephemeral_pubkey"`
603596
DecryptedData string `json:"decrypted_data"`
604597
NextEphemeralPubKey string `json:"next_ephemeral_pubkey"`
@@ -610,31 +603,27 @@ type hopData struct {
610603
EncodedTLVs string `json:"encoded_tlvs"`
611604
}
612605

613-
//nolint:tagliatelle
614606
type hopOnionMessageData struct {
615607
PathKeySecret string `json:"path_key_secret"`
616608
EncodedOnionMessageTLVs encodedOnionMessageTLVs `json:"tlvs"`
617609
EncryptedDataTlv string `json:"encrypted_data_tlv"` //nolint:lll
618-
EphemeralPubKey string `json:"E"`
610+
EphemeralPubKey string `json:"E"` //nolint:tagliatelle
619611
NextEphemeralPrivKey string `json:"next_e"`
620612
EncryptedRecipientData string `json:"encrypted_recipient_data"` //nolint:lll
621613
}
622614

623-
//nolint:tagliatelle
624615
type encodedOnionMessageTLVs struct {
625616
NextNodeID string `json:"next_node_id"`
626617
NextPathKeyOverride string `json:"next_path_key_override"`
627618
PathKeyOverrideSecret string `json:"path_key_override_secret"`
628619
PathID string `json:"path_id"`
629620
}
630621

631-
//nolint:tagliatelle
632622
type blindedHop struct {
633623
BlindedNodeID string `json:"blinded_node_id"`
634624
EncryptedData string `json:"encrypted_data"`
635625
}
636626

637-
//nolint:tagliatelle
638627
type blindedOnionMessageHop struct {
639628
BlindedNodeID string `json:"blinded_node_id"`
640629
EncryptedRecipientData string `json:"encrypted_recipient_data"`

sphinx.go

Lines changed: 8 additions & 5 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,20 +402,23 @@ 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

413-
_, err := w.Write(f.RoutingInfo)
415+
_, err = w.Write(f.RoutingInfo)
414416
if err != nil {
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)