Skip to content

Commit 9260f57

Browse files
committed
initialize NewOnionErrorEncrypter with shared secret directly
Allow for more flexible usage of the error encrypter. This is useful when upgrading an existing legacy error encrypter to fat errors in lnd.
1 parent 371dfed commit 9260f57

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

obfuscation.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,10 @@ type OnionErrorEncrypter struct {
1515
// NewOnionErrorEncrypter creates new instance of the onion encrypter backed by
1616
// the passed router, with encryption to be doing using the passed
1717
// ephemeralKey.
18-
func NewOnionErrorEncrypter(router *Router,
19-
ephemeralKey *btcec.PublicKey) (*OnionErrorEncrypter, error) {
20-
21-
sharedSecret, err := router.generateSharedSecret(ephemeralKey)
22-
if err != nil {
23-
return nil, err
24-
}
25-
18+
func NewOnionErrorEncrypter(sharedSecret Hash256) *OnionErrorEncrypter {
2619
return &OnionErrorEncrypter{
2720
sharedSecret: sharedSecret,
28-
}, nil
21+
}
2922
}
3023

3124
// Encode writes the encrypter's shared secret to the provided io.Writer.

obfuscation_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ func TestOnionFailure(t *testing.T) {
3434
}
3535

3636
// Emulate creation of the obfuscator on node where error have occurred.
37-
obfuscator := &OnionErrorEncrypter{
38-
sharedSecret: sharedSecrets[len(errorPath)-1],
39-
}
37+
obfuscator := NewOnionErrorEncrypter(sharedSecrets[len(errorPath)-1])
4038

4139
// Emulate the situation when last hop creates the onion failure
4240
// message and send it back.
@@ -46,9 +44,7 @@ func TestOnionFailure(t *testing.T) {
4644
for i := len(errorPath) - 2; i >= 0; i-- {
4745
// Emulate creation of the obfuscator on forwarding node which
4846
// propagates the onion failure.
49-
obfuscator = &OnionErrorEncrypter{
50-
sharedSecret: sharedSecrets[i],
51-
}
47+
obfuscator = NewOnionErrorEncrypter(sharedSecrets[i])
5248
obfuscatedData = obfuscator.EncryptError(false, obfuscatedData)
5349
}
5450

@@ -207,16 +203,16 @@ func TestOnionFailureSpecVector(t *testing.T) {
207203
t.Fatalf("unable to decode spec shared secret: %v",
208204
err)
209205
}
210-
obfuscator := &OnionErrorEncrypter{
211-
sharedSecret: sharedSecrets[len(sharedSecrets)-1-i],
212-
}
206+
obfuscator := NewOnionErrorEncrypter(
207+
sharedSecrets[len(sharedSecrets)-1-i],
208+
)
213209

214210
var b bytes.Buffer
215211
if err := obfuscator.Encode(&b); err != nil {
216212
t.Fatalf("unable to encode obfuscator: %v", err)
217213
}
218214

219-
obfuscator2 := &OnionErrorEncrypter{}
215+
obfuscator2 := NewOnionErrorEncrypter(Hash256{})
220216
obfuscatorReader := bytes.NewReader(b.Bytes())
221217
if err := obfuscator2.Decode(obfuscatorReader); err != nil {
222218
t.Fatalf("unable to decode obfuscator: %v", err)

0 commit comments

Comments
 (0)