Refactored onion generators into onion types

This commit is contained in:
херетик
2023-06-01 08:11:28 +01:00
parent d242bd4874
commit 745db8f27a
20 changed files with 186 additions and 147 deletions

View File

@@ -66,7 +66,7 @@ func TestDispatcher(t *testing.T) {
Confirmation(id1, load1).
Assemble()
on2 := onions.Skins{}.
Response(id2, msg1, 0).
Response(id2, msg1, 0, 0).
Assemble()
s1 := onions.Encode(on1)
s2 := onions.Encode(on2)
@@ -187,10 +187,10 @@ func TestDispatcher_Rekey(t *testing.T) {
var msgp1, msgp2 slice.Bytes
id1, id2 := nonce.NewID(), nonce.NewID()
on1 := onions.Skins{}.
Response(id1, msg1, 0).
Response(id1, msg1, 0, 0).
Assemble()
on2 := onions.Skins{}.
Response(id2, msg2, 0).
Response(id2, msg2, 0, 0).
Assemble()
s1 := onions.Encode(on1)
s2 := onions.Encode(on2)

View File

@@ -39,7 +39,7 @@ func (ng *Engine) BuyNewSessions(amount lnwire.MilliSatoshi,
conf := nonce.NewID()
var s [5]*onions2.Session
for i := range s {
s[i] = onions2.NewSessionKeys(byte(i))
s[i] = onions2.NewSession(byte(i)).(*onions2.Session)
}
var confirmChans [5]chan bool
var pendingConfirms int

View File

@@ -93,5 +93,10 @@ func (x *Balance) Handle(s *splice.Splice, p Onion, ng Ngin) (e error) {
func (x *Balance) Len() int { return BalanceLen }
func (x *Balance) Magic() string { return BalanceMagic }
func (x *Balance) Wrap(inner Onion) {}
func balanceGen() coding.Codec { return &Balance{} }
func init() { reg.Register(BalanceMagic, balanceGen) }
func NewBalance(id nonce.ID, amt lnwire.MilliSatoshi) Onion {
return &Balance{ID: id, MilliSatoshi: amt}
}
func balanceGen() coding.Codec { return &Balance{} }
func init() { reg.Register(BalanceMagic, balanceGen) }

View File

@@ -36,9 +36,6 @@ func (x *Confirmation) Decode(s *splice.Splice) (e error) {
}
func (x *Confirmation) Encode(s *splice.Splice) (e error) {
// log.T.S("encoding", reflect.TypeOf(x),
// x.Keys, x.Load,
// )
s.Magic(ConfirmationMagic).ID(x.ID).Byte(x.Load)
return
}
@@ -52,8 +49,9 @@ func (x *Confirmation) Handle(s *splice.Splice, p Onion, ng Ngin) (e error) {
return
}
func (x *Confirmation) Len() int { return ConfirmationLen }
func (x *Confirmation) Magic() string { return ConfirmationMagic }
func (x *Confirmation) Wrap(inner Onion) {}
func confirmationGen() coding.Codec { return &Confirmation{} }
func init() { reg.Register(ConfirmationMagic, confirmationGen) }
func (x *Confirmation) Len() int { return ConfirmationLen }
func (x *Confirmation) Magic() string { return ConfirmationMagic }
func (x *Confirmation) Wrap(inner Onion) {}
func NewConfirmation(id nonce.ID, load byte) Onion { return &Confirmation{ID: id, Load: load} }
func confirmationGen() coding.Codec { return &Confirmation{} }
func init() { reg.Register(ConfirmationMagic, confirmationGen) }

View File

@@ -134,5 +134,18 @@ func (x *Crypt) Handle(s *splice.Splice, p Onion, ng Ngin) (e error) {
func (x *Crypt) Len() int { return CryptLen + x.Onion.Len() }
func (x *Crypt) Magic() string { return CryptMagic }
func (x *Crypt) Wrap(inner Onion) { x.Onion = inner }
func cryptGen() coding.Codec { return &Crypt{} }
func init() { reg.Register(CryptMagic, cryptGen) }
func NewCrypt(toHdr, toPld *crypto.Pub, from *crypto.Prv, iv nonce.IV,
depth int) Onion {
return &Crypt{
Depth: depth,
ToHeaderPub: toHdr,
ToPayloadPub: toPld,
From: from,
IV: iv,
Onion: nop,
}
}
func cryptGen() coding.Codec { return &Crypt{} }
func init() { reg.Register(CryptMagic, cryptGen) }

View File

@@ -59,8 +59,9 @@ func (x *Delay) Handle(s *splice.Splice, p Onion, ng Ngin) (e error) {
return
}
func (x *Delay) Len() int { return DelayLen + x.Onion.Len() }
func (x *Delay) Magic() string { return DelayMagic }
func (x *Delay) Wrap(inner Onion) { x.Onion = inner }
func delayGen() coding.Codec { return &Delay{} }
func init() { reg.Register(DelayMagic, delayGen) }
func (x *Delay) Len() int { return DelayLen + x.Onion.Len() }
func (x *Delay) Magic() string { return DelayMagic }
func (x *Delay) Wrap(inner Onion) { x.Onion = inner }
func NewDelay(d time.Duration) Onion { return &Delay{Duration: d, Onion: &End{}} }
func delayGen() coding.Codec { return &Delay{} }
func init() { reg.Register(DelayMagic, delayGen) }

View File

@@ -156,7 +156,30 @@ type ExitParams struct {
S sessions.Circuit
KS *crypto.KeySet
}
type ExitPoint struct {
*Routing
ReturnPubs crypto.Pubs
}
func (x *Exit) Wrap(inner Onion) { x.Onion = inner }
func exitGen() coding.Codec { return &Exit{} }
func init() { reg.Register(ExitMagic, exitGen) }
type Routing struct {
Sessions [3]*sessions.Data
Keys crypto.Privs
crypto.Nonces
}
func NewExit(id nonce.ID, port uint16, payload slice.Bytes,
ep *ExitPoint) Onion {
return &Exit{
ID: id,
Ciphers: crypto.GenCiphers(ep.Keys, ep.ReturnPubs),
Nonces: ep.Nonces,
Port: port,
Bytes: payload,
Onion: &End{},
}
}
func exitGen() coding.Codec { return &Exit{} }
func init() { reg.Register(ExitMagic, exitGen) }

View File

@@ -72,8 +72,9 @@ func (x *Forward) Handle(s *splice.Splice, p Onion, ng Ngin) (e error) {
return e
}
func (x *Forward) Len() int { return ForwardLen + x.Onion.Len() }
func (x *Forward) Magic() string { return ForwardMagic }
func (x *Forward) Wrap(inner Onion) { x.Onion = inner }
func forwardGen() coding.Codec { return &Forward{} }
func init() { reg.Register(ForwardMagic, forwardGen) }
func (x *Forward) Len() int { return ForwardLen + x.Onion.Len() }
func (x *Forward) Magic() string { return ForwardMagic }
func (x *Forward) Wrap(inner Onion) { x.Onion = inner }
func NewForward(addr *netip.AddrPort) Onion { return &Forward{AddrPort: addr, Onion: &End{}} }
func forwardGen() coding.Codec { return &Forward{} }
func init() { reg.Register(ForwardMagic, forwardGen) }

View File

@@ -126,5 +126,13 @@ type GetBalanceParams struct {
}
func (x *GetBalance) Wrap(inner Onion) { x.Onion = inner }
func NewGetBalance(id nonce.ID, ep *ExitPoint) Onion {
return &GetBalance{
ID: id,
Ciphers: crypto.GenCiphers(ep.Keys, ep.ReturnPubs),
Nonces: ep.Nonces,
Onion: nop,
}
}
func getBalanceGen() coding.Codec { return &GetBalance{} }
func init() { reg.Register(GetBalanceMagic, getBalanceGen) }

View File

@@ -88,5 +88,13 @@ func (x *HiddenService) Len() int { return HiddenServiceLen + x.Onion.Le
func (x *HiddenService) Magic() string { return HiddenServiceMagic }
func (x *HiddenService) Wrap(inner Onion) { x.Onion = inner }
func NewHiddenService(in *intro.Ad, point *ExitPoint) Onion {
return &HiddenService{
Intro: *in,
Ciphers: crypto.GenCiphers(point.Keys, point.ReturnPubs),
Nonces: point.Nonces,
Onion: NewEnd(),
}
}
func hiddenServiceGen() coding.Codec { return &HiddenService{} }
func init() { reg.Register(HiddenServiceMagic, hiddenServiceGen) }

View File

@@ -104,5 +104,16 @@ func (x *IntroQuery) Handle(s *splice.Splice, p Onion, ng Ngin) (e error) {
func (x *IntroQuery) Len() int { return IntroQueryLen + x.Onion.Len() }
func (x *IntroQuery) Magic() string { return IntroQueryMagic }
func (x *IntroQuery) Wrap(inner Onion) { x.Onion = inner }
func init() { reg.Register(IntroQueryMagic, introQueryGen) }
func introQueryGen() coding.Codec { return &IntroQuery{} }
func NewIntroQuery(id nonce.ID, hsk *crypto.Pub, exit *ExitPoint) Onion {
return &IntroQuery{
ID: id,
Ciphers: crypto.GenCiphers(exit.Keys, exit.ReturnPubs),
Nonces: exit.Nonces,
Key: hsk,
Onion: NewEnd(),
}
}
func init() { reg.Register(IntroQueryMagic, introQueryGen) }
func introQueryGen() coding.Codec { return &IntroQuery{} }

View File

@@ -43,36 +43,22 @@ func (o Skins) Assemble() (on Onion) {
}
func (o Skins) Balance(id nonce.ID, amt lnwire.MilliSatoshi) Skins {
return append(o, &Balance{ID: id, MilliSatoshi: amt})
return append(o, NewBalance(id, amt))
}
func (o Skins) Confirmation(id nonce.ID, load byte) Skins {
return append(o, &Confirmation{ID: id, Load: load})
return append(o, NewConfirmation(id, load))
}
func (o Skins) Crypt(toHdr, toPld *crypto.Pub, from *crypto.Prv, iv nonce.IV,
depth int) Skins {
return append(o, &Crypt{
Depth: depth,
ToHeaderPub: toHdr,
ToPayloadPub: toPld,
From: from,
IV: iv,
Onion: nop,
})
return append(o, NewCrypt(toHdr, toPld, from, iv, depth))
}
func (o Skins) Delay(d time.Duration) Skins {
return append(o, &Delay{Duration: d, Onion: nop})
}
func (o Skins) Delay(d time.Duration) Skins { return append(o, NewDelay(d)) }
type (
ExitPoint struct {
*Routing
ReturnPubs crypto.Pubs
}
Skins []Onion
Headers struct {
Forward, Return *Routing
@@ -93,11 +79,6 @@ type (
*Reverse
*Crypt
}
Routing struct {
Sessions [3]*sessions.Data
Keys crypto.Privs
crypto.Nonces
}
RoutingHeader struct {
Layers [3]RoutingLayer
}
@@ -116,14 +97,7 @@ func (o Skins) End() Skins {
func (o Skins) Exit(id nonce.ID, port uint16, payload slice.Bytes,
ep *ExitPoint) Skins {
return append(o, &Exit{
ID: id,
Ciphers: crypto.GenCiphers(ep.Keys, ep.ReturnPubs),
Nonces: ep.Nonces,
Port: port,
Bytes: payload,
Onion: nop,
})
return append(o, NewExit(id, port, payload, ep))
}
func FormatReply(header RoutingHeaderBytes, ciphers crypto.Ciphers,
@@ -140,9 +114,7 @@ func FormatReply(header RoutingHeaderBytes, ciphers crypto.Ciphers,
return
}
func (o Skins) Forward(addr *netip.AddrPort) Skins {
return append(o, &Forward{AddrPort: addr, Onion: &End{}})
}
func (o Skins) Forward(addr *netip.AddrPort) Skins { return append(o, NewForward(addr)) }
func (o Skins) ForwardCrypt(s *sessions.Data, k *crypto.Prv, n nonce.IV) Skins {
return o.Forward(s.Node.AddrPort).Crypt(s.Header.Pub, s.Payload.Pub, k,
@@ -157,14 +129,7 @@ func (o Skins) ForwardSession(s *node.Node,
Session(sess)
}
func (o Skins) GetBalance(id nonce.ID, ep *ExitPoint) Skins {
return append(o, &GetBalance{
ID: id,
Ciphers: crypto.GenCiphers(ep.Keys, ep.ReturnPubs),
Nonces: ep.Nonces,
Onion: nop,
})
}
func (o Skins) GetBalance(id nonce.ID, ep *ExitPoint) Skins { return append(o, NewGetBalance(id, ep)) }
func GetHeaders(alice, bob *sessions.Data, c sessions.Circuit,
ks *crypto.KeySet) (h *Headers) {
@@ -215,22 +180,11 @@ func (h *Headers) ExitPoint() *ExitPoint {
}
func (o Skins) HiddenService(in *intro.Ad, point *ExitPoint) Skins {
return append(o, &HiddenService{
Intro: *in,
Ciphers: crypto.GenCiphers(point.Keys, point.ReturnPubs),
Nonces: point.Nonces,
Onion: NewEnd(),
})
return append(o, NewHiddenService(in, point))
}
func (o Skins) IntroQuery(id nonce.ID, hsk *crypto.Pub, exit *ExitPoint) Skins {
return append(o, &IntroQuery{
ID: id,
Ciphers: crypto.GenCiphers(exit.Keys, exit.ReturnPubs),
Nonces: exit.Nonces,
Key: hsk,
Onion: nop,
})
return append(o, NewIntroQuery(id, hsk, exit))
}
// MakeExit constructs a message containing an arbitrary payload to a node (3rd
@@ -347,22 +301,17 @@ func ReadRoutingHeader(s *splice.Splice, b *RoutingHeaderBytes) *splice.Splice {
return s
}
func (o Skins) Ready(id nonce.ID, addr *crypto.Pub, fwHeader,
rvHeader RoutingHeaderBytes,
fc, rc crypto.Ciphers, fn, rn crypto.Nonces) Skins {
return append(o, &Ready{id, addr,
&ReplyHeader{fwHeader, fc, fn},
&ReplyHeader{rvHeader, rc, rn},
})
func (o Skins) Ready(id nonce.ID, addr *crypto.Pub, fwHdr,
rvHdr RoutingHeaderBytes, fc, rc crypto.Ciphers, fn, rn crypto.Nonces) Skins {
return append(o, NewReady(id, addr, fwHdr, rvHdr, fc, rc, fn, rn))
}
func (o Skins) Response(id nonce.ID, res slice.Bytes, port uint16) Skins {
return append(o, &Response{ID: id, Port: port, Bytes: res})
func (o Skins) Response(id nonce.ID, res slice.Bytes, port uint16, load byte) Skins {
return append(o, NewResponse(id, port, res, load))
}
func (o Skins) Reverse(ip *netip.AddrPort) Skins {
return append(o, &Reverse{AddrPort: ip, Onion: nop})
}
func (o Skins) Reverse(ip *netip.AddrPort) Skins { return append(o, NewReverse(ip)) }
func (o Skins) ReverseCrypt(s *sessions.Data, k *crypto.Prv, n nonce.IV,
seq int) (oo Skins) {
@@ -376,21 +325,8 @@ func (o Skins) ReverseCrypt(s *sessions.Data, k *crypto.Prv, n nonce.IV,
seq)
}
func (o Skins) Route(id nonce.ID, k *crypto.Pub, ks *crypto.KeySet,
ep *ExitPoint) Skins {
oo := &Route{
HiddenService: k,
Sender: ks.Next(),
IV: nonce.New(),
ID: id,
Ciphers: crypto.GenCiphers(ep.Keys, ep.ReturnPubs),
Nonces: ep.Nonces,
Onion: &End{},
}
oo.SenderPub = crypto.DerivePub(oo.Sender)
oo.HiddenCloaked = crypto.GetCloak(k)
return append(o, oo)
func (o Skins) Route(id nonce.ID, k *crypto.Pub, ks *crypto.KeySet, ep *ExitPoint) Skins {
return append(o, NewRoute(id, k, ks, ep))
}
func (o Skins) RoutingHeader(r *Routing) Skins {
@@ -406,11 +342,7 @@ func (o Skins) Session(sess *Session) Skins {
if sess.Header == nil || sess.Payload == nil {
return o
}
return append(o, &Session{
Header: sess.Header,
Payload: sess.Payload,
Onion: &End{},
})
return append(o, sess)
}
func WriteRoutingHeader(s *splice.Splice, b RoutingHeaderBytes) *splice.Splice {

View File

@@ -65,7 +65,6 @@ func (x *Ready) Encode(s *splice.Splice) (e error) {
return
}
func ReadyGen() coding.Codec { return &Ready{} }
func (x *Ready) GetOnion() interface{} { return x }
func (x *Ready) Handle(s *splice.Splice, p Onion, ng Ngin) (e error) {
@@ -76,4 +75,18 @@ func (x *Ready) Handle(s *splice.Splice, p Onion, ng Ngin) (e error) {
func (x *Ready) Len() int { return ReadyLen }
func (x *Ready) Magic() string { return ReadyMagic }
func (x *Ready) Wrap(inner Onion) {}
func init() { reg.Register(ReadyMagic, ReadyGen) }
func NewReady(
id nonce.ID,
addr *crypto.Pub,
fwHeader,
rvHeader RoutingHeaderBytes,
fc, rc crypto.Ciphers,
fn, rn crypto.Nonces,
)Onion{return &Ready{id, addr,
&ReplyHeader{fwHeader, fc, fn},
&ReplyHeader{rvHeader, rc, rn},
}}
func init() { reg.Register(ReadyMagic, readyGen) }
func readyGen() coding.Codec { return &Ready{} }

View File

@@ -14,7 +14,9 @@ import (
const (
ResponseMagic = "resp"
ResponseLen = magic.Len + slice.Uint32Len + slice.Uint16Len +
ResponseLen = magic.Len +
slice.Uint32Len +
slice.Uint16Len +
nonce.IDLen + 1
)
@@ -25,6 +27,10 @@ type Response struct {
slice.Bytes
}
func NewResponse(id nonce.ID, port uint16, res slice.Bytes, load byte) Onion {
return &Response{ID: id, Port: port, Bytes: res, Load: load}
}
func (x *Response) Account(res *sess.Data, sm *sess.Manager,
s *sessions.Data, last bool) (skip bool, sd *sessions.Data) {
return
@@ -92,5 +98,5 @@ func (x *Response) Handle(s *splice.Splice, p Onion, ng Ngin) (e error) {
func (x *Response) Len() int { return ResponseLen + len(x.Bytes) }
func (x *Response) Magic() string { return ResponseMagic }
func (x *Response) Wrap(inner Onion) {}
func init() { reg.Register(ResponseMagic, responseGen) }
func responseGen() coding.Codec { return &Response{} }
func init() { reg.Register(ResponseMagic, responseGen) }
func responseGen() coding.Codec { return &Response{} }

View File

@@ -23,7 +23,7 @@ func TestOnions_Response(t *testing.T) {
}
port := uint16(cryptorand.IntN(65536))
on := Skins{}.
Response(id, msg, port).
Response(id, msg, port, 0).
End().Assemble()
s := Encode(on)
s.SetCursor(0)

View File

@@ -23,6 +23,8 @@ type Reverse struct {
Onion
}
func NewReverse(ip *netip.AddrPort) Onion { return &Reverse{AddrPort: ip, Onion: NewEnd()} }
func (x *Reverse) Account(res *sess.Data, sm *sess.Manager,
s *sessions.Data, last bool) (skip bool, sd *sessions.Data) {
res.Billable = append(res.Billable, s.Header.Bytes)

View File

@@ -17,8 +17,13 @@ import (
const (
RouteMagic = "rout"
RouteLen = magic.Len + crypto.CloakLen + crypto.PubKeyLen + nonce.IVLen +
nonce.IDLen + 3*sha256.Len + 3*nonce.IVLen
RouteLen = magic.Len +
crypto.CloakLen +
crypto.PubKeyLen +
nonce.IVLen +
nonce.IDLen +
3*sha256.Len +
3*nonce.IVLen
)
type Route struct {
@@ -40,6 +45,22 @@ type Route struct {
Onion
}
func NewRoute(id nonce.ID, k *crypto.Pub, ks *crypto.KeySet,
ep *ExitPoint) Onion {
oo := &Route{
HiddenService: k,
Sender: ks.Next(),
IV: nonce.New(),
ID: id,
Ciphers: crypto.GenCiphers(ep.Keys, ep.ReturnPubs),
Nonces: ep.Nonces,
Onion: &End{},
}
oo.SenderPub = crypto.DerivePub(oo.Sender)
oo.HiddenCloaked = crypto.GetCloak(k)
return oo
}
func (x *Route) Account(res *sess.Data, sm *sess.Manager,
s *sessions.Data, last bool) (skip bool, sd *sessions.Data) {
copy(res.ID[:], x.ID[:])

View File

@@ -25,7 +25,7 @@ type Session struct {
Onion
}
func NewSessionKeys(hop byte) (x *Session) {
func NewSession(hop byte) (x Onion) {
var e error
var hdr, pld *crypto.Keys
if hdr, pld, e = crypto.Generate2Keys(); fails(e) {
@@ -36,6 +36,7 @@ func NewSessionKeys(hop byte) (x *Session) {
Hop: hop,
Header: hdr,
Payload: pld,
Onion: NewEnd(),
}
}

View File

@@ -10,10 +10,9 @@ import (
func TestOnions_Session(t *testing.T) {
log2.SetLogLevel(log2.Debug)
sess := NewSessionKeys(1)
on := Skins{}.
Session(sess).
Assemble()
sess := NewSession(1)
ss := sess.(*Session)
on := Skins{sess}.Assemble()
s := Encode(on)
s.SetCursor(0)
var onc coding.Codec
@@ -32,11 +31,11 @@ func TestOnions_Session(t *testing.T) {
t.Error("did not unwrap expected type")
t.FailNow()
}
if !ci.Header.Prv.Equals(sess.Header.Prv) {
if !ci.Header.Prv.Equals(ss.Header.Prv) {
t.Error("header key did not unwrap correctly")
t.FailNow()
}
if !ci.Payload.Prv.Equals(sess.Payload.Prv) {
if !ci.Payload.Prv.Equals(ss.Payload.Prv) {
t.Error("payload key did not unwrap correctly")
t.FailNow()
}

View File

@@ -3,6 +3,7 @@ package splice
import (
"encoding/hex"
"fmt"
"github.com/gookit/color"
"github.com/indra-labs/indra"
"github.com/indra-labs/indra/pkg/crypto"
"github.com/indra-labs/indra/pkg/crypto/nonce"
@@ -12,7 +13,6 @@ import (
"github.com/indra-labs/indra/pkg/util/b32/based32"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/gookit/color"
"net"
"net/netip"
"sort"
@@ -40,6 +40,7 @@ type (
b slice.Bytes
c *slice.Cursor
Segments
E error
}
)
@@ -52,11 +53,11 @@ func BudgeUp(s *Splice) (o *Splice) {
}
func Load(b slice.Bytes, c *slice.Cursor) (splicer *Splice) {
return &Splice{b, c, Segments{}}
return &Splice{b, c, Segments{}, nil}
}
func New(length int) (splicer *Splice) {
splicer = &Splice{make(slice.Bytes, length), slice.NewCursor(), Segments{}}
splicer = &Splice{make(slice.Bytes, length), slice.NewCursor(), Segments{}, nil}
return
}
@@ -70,8 +71,7 @@ func (s *Splice) AddrPort(a *netip.AddrPort) *Splice {
return s
}
var ap []byte
var e error
if ap, e = a.MarshalBinary(); fails(e) {
if ap, s.E = a.MarshalBinary(); fails(s.E) {
return s
}
s.b[*s.c] = byte(len(ap))
@@ -89,7 +89,7 @@ func (s *Splice) Advance(n int, name string) int {
}
func (s *Splice) Byte(b byte) *Splice {
s.b[*s.c] = byte(b)
s.b[*s.c] = b
s.c.Inc(1)
s.Segments = append(s.Segments,
NameOffset{Offset: int(*s.c), Name: "byte"})
@@ -274,7 +274,7 @@ func (s *Splice) ReadAddrPort(ap **netip.AddrPort) *Splice {
*ap = &netip.AddrPort{}
apLen := s.b[*s.c]
apBytes := s.b[s.c.Inc(1):s.c.Inc(AddrLen)]
if e := (*ap).UnmarshalBinary(apBytes[:apLen]); fails(e) {
if s.E = (*ap).UnmarshalBinary(apBytes[:apLen]); fails(s.E) {
}
s.Segments = append(s.Segments,
NameOffset{Offset: int(*s.c),
@@ -382,8 +382,7 @@ func (s *Splice) ReadPrvkey(out **crypto.Prv) *Splice {
func (s *Splice) ReadPubkey(from **crypto.Pub) *Splice {
var f *crypto.Pub
var e error
if f, e = crypto.PubFromBytes(s.b[*s.c:s.c.Inc(crypto.PubKeyLen)]); !fails(e) {
if f, s.E = crypto.PubFromBytes(s.b[*s.c:s.c.Inc(crypto.PubKeyLen)]); !fails(s.E) {
*from = f
}
s.Segments = append(s.Segments,
@@ -508,9 +507,8 @@ func (s *Splice) String() (o string) {
}
if prevString == "pubkey" {
var oo string
var e error
if oo, e = based32.Codec.Encode(v.ToBytes()); fails(e) {
o += "<error: " + e.Error() + " >"
if oo, s.E = based32.Codec.Encode(v.ToBytes()); fails(s.E) {
o += "<error: " + s.E.Error() + " >"
}
oo = oo[3:]
tmp := make(slice.Bytes, 0, len(oo))
@@ -521,9 +519,8 @@ func (s *Splice) String() (o string) {
}
if prevString == "Keys" {
var oo string
var e error
if oo, e = based32.Codec.Encode(v.ToBytes()); fails(e) {
o += "<error: " + e.Error() + " >"
if oo, s.E = based32.Codec.Encode(v.ToBytes()); fails(s.E) {
o += "<error: " + s.E.Error() + " >"
}
o += color.LightBlue.Sprint(oo[:13])
}