Testing cipher and confirmation

This commit is contained in:
David Vennik
2022-12-24 11:16:03 +00:00
parent ff14a362f1
commit c2b60d9919
14 changed files with 162 additions and 121 deletions

View File

@@ -2,7 +2,6 @@ package cipher
import (
"github.com/Indra-Labs/indra"
"github.com/Indra-Labs/indra/pkg/key/prv"
"github.com/Indra-Labs/indra/pkg/key/pub"
"github.com/Indra-Labs/indra/pkg/slice"
"github.com/Indra-Labs/indra/pkg/types"
@@ -15,11 +14,11 @@ var (
check = log.E.Chk
MagicString = "cf"
Magic = slice.Bytes(MagicString)
MinLen = magicbytes.Len + prv.KeyLen*2
_ types.Onion = &Type{}
MinLen = magicbytes.Len + pub.KeyLen*2
_ types.Onion = &OnionSkin{}
)
// Type cipher delivers a pair of private keys to be used in association with a
// OnionSkin cipher delivers a pair of private keys to be used in association with a
// reply.Type specifically in the situation of a node bootstrapping sessions.
//
// After ~10 seconds these can be purged from the cache as they are otherwise a
@@ -28,33 +27,31 @@ var (
// The Decode function wipes the original message data for security as the
// private keys inside it are no longer needed and any secret should only have
// one storage, so it doesn't appear in any GC later.
type Type struct {
type OnionSkin struct {
Header, Payload *pub.Key
types.Onion
}
func (x *Type) Inner() types.Onion { return x.Onion }
func (x *Type) Insert(o types.Onion) { x.Onion = o }
func (x *Type) Len() int {
return magicbytes.Len + pub.KeyLen + x.Onion.Len()
}
func (x *OnionSkin) Inner() types.Onion { return x.Onion }
func (x *OnionSkin) Insert(o types.Onion) { x.Onion = o }
func (x *OnionSkin) Len() int { return MinLen + x.Onion.Len() }
func (x *Type) Encode(b slice.Bytes, c *slice.Cursor) {
func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
hdr := x.Header.ToBytes()
pld := x.Payload.ToBytes()
copy(b[c.Inc(1):c.Inc(pub.KeyLen)], hdr[:])
copy(b[c.Inc(1):c.Inc(pub.KeyLen)], pld[:])
copy(b[*c:c.Inc(pub.KeyLen)], hdr[:])
copy(b[*c:c.Inc(pub.KeyLen)], pld[:])
x.Onion.Encode(b, c)
}
// Decode unwraps a cipher.Type message.
func (x *Type) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen {
return magicbytes.TooShort(len(b[*c:]), MinLen, string(Magic))
// Decode unwraps a cipher.OnionSkin message.
func (x *OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen-magicbytes.Len {
return magicbytes.TooShort(len(b[*c:]),
MinLen-magicbytes.Len, string(Magic))
}
start := c.Inc(magicbytes.Len)
x.Header, e = pub.FromBytes(b[start:c.Inc(pub.KeyLen)])
x.Header, e = pub.FromBytes(b[*c:c.Inc(pub.KeyLen)])
x.Payload, e = pub.FromBytes(b[*c:c.Inc(pub.KeyLen)])
return
}

View File

@@ -34,61 +34,61 @@ func EncodeOnion(on types.Onion) (b slice.Bytes) {
func PeelOnion(b slice.Bytes, c *slice.Cursor) (on types.Onion, e error) {
switch b[*c:c.Inc(magicbytes.Len)].String() {
case cipher.MagicString:
var o cipher.Type
var o cipher.OnionSkin
if e = o.Decode(b, c); check(e) {
return
}
on = &o
case confirmation.MagicString:
var o confirmation.Type
var o confirmation.OnionSkin
if e = o.Decode(b, c); check(e) {
return
}
on = &o
case exit.MagicString:
var o exit.Type
var o exit.OnionSkin
if e = o.Decode(b, c); check(e) {
return
}
on = &o
case forward.MagicString:
var o forward.Type
var o forward.OnionSkin
if e = o.Decode(b, c); check(e) {
return
}
on = &o
case message.MagicString:
var o message.Type
var o message.OnionSkin
if e = o.Decode(b, c); check(e) {
return
}
on = &o
case purchase.MagicString:
var o purchase.Type
var o purchase.OnionSkin
if e = o.Decode(b, c); check(e) {
return
}
on = &o
case reply.MagicString:
var o reply.Type
var o reply.OnionSkin
if e = o.Decode(b, c); check(e) {
return
}
on = &o
case response.MagicString:
var o response.Response
var o response.OnionSkin
if e = o.Decode(b, c); check(e) {
return
}
on = o
case session.MagicString:
var o session.Type
var o session.OnionSkin
if e = o.Decode(b, c); check(e) {
return
}
on = &o
case token.MagicString:
var o token.Type
var o token.OnionSkin
if e = o.Decode(b, c); check(e) {
return
}

View File

@@ -2,10 +2,42 @@ package wire
import (
"testing"
"github.com/Indra-Labs/indra/pkg/key/prv"
"github.com/Indra-Labs/indra/pkg/key/pub"
"github.com/Indra-Labs/indra/pkg/nonce"
"github.com/Indra-Labs/indra/pkg/slice"
"github.com/Indra-Labs/indra/pkg/types"
"github.com/Indra-Labs/indra/pkg/wire/cipher"
"github.com/Indra-Labs/indra/pkg/wire/confirmation"
log2 "github.com/cybriq/proc/pkg/log"
)
func TestOnionSkins_Cipher(t *testing.T) {
log2.CodeLoc = true
var e error
hdrP, pldP := GetTwoPrvKeys(t)
hdr, pld := pub.Derive(hdrP), pub.Derive(pldP)
log.I.S(hdr, pld)
n := nonce.NewID()
log.I.S(n)
on := OnionSkins{}.
Cipher(hdr, pld).
Confirmation(n).
Assemble()
onb := EncodeOnion(on)
var sc slice.Cursor
c := &sc
var onc types.Onion
if onc, e = PeelOnion(onb, c); check(e) {
t.FailNow()
}
log.I.S(onc.(*cipher.OnionSkin))
var oncn types.Onion
if oncn, e = PeelOnion(onb, c); check(e) {
t.FailNow()
}
log.I.S(oncn.(*confirmation.OnionSkin))
}
func TestOnionSkins_Confirmation(t *testing.T) {
@@ -43,3 +75,14 @@ func TestOnionSkins_Session(t *testing.T) {
func TestOnionSkins_Token(t *testing.T) {
}
func GetTwoPrvKeys(t *testing.T) (prv1, prv2 *prv.Key) {
var e error
if prv1, e = prv.GenerateKey(); check(e) {
t.FailNow()
}
if prv2, e = prv.GenerateKey(); check(e) {
t.FailNow()
}
return
}

View File

@@ -15,10 +15,10 @@ var (
MagicString = "cn"
Magic = slice.Bytes(MagicString)
MinLen = magicbytes.Len + nonce.IDLen
_ types.Onion = &Type{}
_ types.Onion = &OnionSkin{}
)
// Type confirmation is an encryption layer for messages returned to the client
// OnionSkin confirmation is an encryption layer for messages returned to the client
// on the inside of an onion, for Ping and Ciphers messages, providing a
// confirmation of the transit of the onion through its encoded route.
//
@@ -30,23 +30,24 @@ var (
// onion - there can be more than one up in the air at a time, but they are
// randomly selected, so they will generally be a much smaller subset versus the
// current full set of Session s currently open.
type Type struct {
type OnionSkin struct {
nonce.ID
}
func (x *Type) Inner() types.Onion { return nil }
func (x *Type) Insert(o types.Onion) {}
func (x *Type) Len() int { return MinLen }
func (x *OnionSkin) Inner() types.Onion { return nil }
func (x *OnionSkin) Insert(o types.Onion) {}
func (x *OnionSkin) Len() int { return MinLen }
func (x *Type) Encode(b slice.Bytes, c *slice.Cursor) {
func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
// Copy in the ID.
copy(b[*c:c.Inc(nonce.IDLen)], x.ID[:])
}
func (x *Type) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen {
return magicbytes.TooShort(len(b[*c:]), MinLen, string(Magic))
func (x *OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen-magicbytes.Len {
return magicbytes.TooShort(len(b[*c:]),
MinLen-magicbytes.Len, string(Magic))
}
copy(x.ID[:], b[*c:c.Inc(nonce.IDLen)])
return

View File

@@ -15,12 +15,12 @@ var (
MagicString = "ex"
Magic = slice.Bytes(MagicString)
MinLen = magicbytes.Len + slice.Uint16Len + 3*sha256.Len
_ types.Onion = &Type{}
_ types.Onion = &OnionSkin{}
)
// Type exit messages are the layer of a message after two Forward packets that
// OnionSkin exit messages are the layer of a message after two Forward packets that
// provides an exit address and
type Type struct {
type OnionSkin struct {
// Port identifies the type of service as well as being the port used by
// the service to be relayed to. Notice there is no IP address, this is
// because Indranet only forwards to exits of decentralised services
@@ -37,14 +37,14 @@ type Type struct {
types.Onion
}
func (x *Type) Inner() types.Onion { return x.Onion }
func (x *Type) Insert(o types.Onion) { x.Onion = o }
func (x *Type) Len() int {
func (x *OnionSkin) Inner() types.Onion { return x.Onion }
func (x *OnionSkin) Insert(o types.Onion) { x.Onion = o }
func (x *OnionSkin) Len() int {
return MinLen + x.Bytes.Len() +
x.Onion.Len()
}
func (x *Type) Encode(b slice.Bytes, c *slice.Cursor) {
func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
port := slice.NewUint16()
slice.EncodeUint16(port, int(x.Port))
@@ -59,7 +59,7 @@ func (x *Type) Encode(b slice.Bytes, c *slice.Cursor) {
x.Onion.Encode(b, c)
}
func (x *Type) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
func (x *OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen {
return magicbytes.TooShort(len(b[*c:]), MinLen, string(Magic))
}

View File

@@ -16,29 +16,29 @@ var (
MagicString = "fw"
Magic = slice.Bytes(MagicString)
MinLen = magicbytes.Len + 1 + net.IPv4len
_ types.Onion = &Type{}
_ types.Onion = &OnionSkin{}
)
// Type forward is just an IP address and a wrapper for another message.
type Type struct {
// OnionSkin forward is just an IP address and a wrapper for another message.
type OnionSkin struct {
net.IP
types.Onion
}
func (x *Type) Inner() types.Onion { return x.Onion }
func (x *Type) Insert(o types.Onion) { x.Onion = o }
func (x *Type) Len() int {
func (x *OnionSkin) Inner() types.Onion { return x.Onion }
func (x *OnionSkin) Insert(o types.Onion) { x.Onion = o }
func (x *OnionSkin) Len() int {
return magicbytes.Len + len(x.IP) + 1 + x.Onion.Len()
}
func (x *Type) Encode(b slice.Bytes, c *slice.Cursor) {
func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
b[*c] = byte(len(x.IP))
copy(b[c.Inc(1):c.Inc(len(x.IP))], x.IP)
x.Onion.Encode(b, c)
}
func (x *Type) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
func (x *OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen {
return magicbytes.TooShort(len(b[*c:]), MinLen, string(Magic))
}

View File

@@ -25,41 +25,41 @@ import (
type OnionSkins []types.Onion
func (o OnionSkins) Cipher(hdr, pld *pub.Key) OnionSkins {
return append(o, &cipher.Type{Header: hdr, Payload: pld})
return append(o, &cipher.OnionSkin{Header: hdr, Payload: pld})
}
func (o OnionSkins) Confirmation(id nonce.ID) OnionSkins {
return append(o, &confirmation.Type{ID: id})
return append(o, &confirmation.OnionSkin{ID: id})
}
func (o OnionSkins) Exit(port uint16, ciphers [3]sha256.Hash,
payload slice.Bytes) OnionSkins {
return append(o, &exit.Type{Port: port, Ciphers: ciphers, Bytes: payload})
return append(o, &exit.OnionSkin{Port: port, Ciphers: ciphers, Bytes: payload})
}
func (o OnionSkins) Forward(ip net.IP) OnionSkins {
return append(o, &forward.Type{IP: ip})
return append(o, &forward.OnionSkin{IP: ip})
}
func (o OnionSkins) Message(to *address.Sender, from *prv.Key) OnionSkins {
return append(o, &message.Type{To: to, From: from})
return append(o, &message.OnionSkin{To: to, From: from})
}
func (o OnionSkins) Purchase(nBytes uint64, ciphers [3]sha256.Hash) OnionSkins {
return append(o, &purchase.Type{NBytes: nBytes, Ciphers: ciphers})
return append(o, &purchase.OnionSkin{NBytes: nBytes, Ciphers: ciphers})
}
func (o OnionSkins) Reply(ip net.IP) OnionSkins {
return append(o, &reply.Type{IP: ip})
return append(o, &reply.OnionSkin{IP: ip})
}
func (o OnionSkins) Response(res slice.Bytes) OnionSkins {
return append(o, response.Response(res))
return append(o, response.OnionSkin(res))
}
func (o OnionSkins) Session(fwd, rtn *pub.Key) OnionSkins {
return append(o, &session.Type{
return append(o, &session.OnionSkin{
HeaderKey: fwd, PayloadKey: rtn,
})
}
func (o OnionSkins) Token(tok sha256.Hash) OnionSkins {
return append(o, token.Type(tok))
return append(o, token.OnionSkin(tok))
}
// Assemble inserts the slice of Onion s inside each other so the first then
// Assemble inserts the slice of OnionSkin s inside each other so the first then
// contains the second, second contains the third, and so on, and then returns
// the first onion, on which you can then call Encode and generate the wire
// message form of the onion.

View File

@@ -22,13 +22,13 @@ var (
check = log.E.Chk
MagicString = "mg"
Magic = slice.Bytes(MagicString)
_ types.Onion = &Type{}
_ types.Onion = &OnionSkin{}
)
// Type message is the generic top level wrapper for an Onion. All following
// OnionSkin message is the generic top level wrapper for an OnionSkin. All following
// messages are wrapped inside this. This type provides the encryption for each
// layer, and a header which a relay uses to determine what cipher to use.
type Type struct {
type OnionSkin struct {
To *address.Sender
From *prv.Key
// The remainder here are for Decode.
@@ -47,13 +47,13 @@ type Type struct {
const MinLen = magicbytes.Len + nonce.IVLen +
address.Len + pub.KeyLen + slice.Uint32Len
func (x *Type) Inner() types.Onion { return x.Onion }
func (x *Type) Insert(o types.Onion) { x.Onion = o }
func (x *Type) Len() int {
func (x *OnionSkin) Inner() types.Onion { return x.Onion }
func (x *OnionSkin) Insert(o types.Onion) { x.Onion = o }
func (x *OnionSkin) Len() int {
return MinLen + x.Onion.Len()
}
func (x *Type) Encode(b slice.Bytes, c *slice.Cursor) {
func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
// The first level message contains the Bytes, but the inner layers do
// not. The inner layers will be passed this buffer, but the first needs
// to have it copied from its original location.
@@ -101,7 +101,7 @@ func (x *Type) Encode(b slice.Bytes, c *slice.Cursor) {
// from the header, a subsequent process must be performed to find the prv.Key
// corresponding to the Cloak and the pub.Key together forming the cipher secret
// needed to decrypt the remainder of the bytes.
func (x *Type) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
func (x *OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen {
return magicbytes.TooShort(len(b[*c:]), MinLen, "message")
}
@@ -136,6 +136,6 @@ func (x *Type) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
// Decrypt requires the prv.Key to be located from the Cloak, using the
// FromPub key to derive the shared secret, and then decrypts the rest of the
// message.
func (x *Type) Decrypt(prk *prv.Key) {
func (x *OnionSkin) Decrypt(prk *prv.Key) {
ciph.Encipher(ciph.GetBlock(prk, x.FromPub), x.Nonce, x.Bytes)
}

View File

@@ -15,13 +15,13 @@ var (
MagicString = "pc"
Magic = slice.Bytes(MagicString)
MinLen = magicbytes.Len + slice.Uint64Len + sha256.Len*3
_ types.Onion = &Type{}
_ types.Onion = &OnionSkin{}
)
// Type purchase is a message that requests a session key, which will activate
// OnionSkin purchase is a message that requests a session key, which will activate
// when a payment for it has been done, or it will time out after some period to
// allow unused codes to be flushed.
type Type struct {
type OnionSkin struct {
NBytes uint64
// Ciphers is a set of 3 symmetric ciphers that are to be used in their
// given order over the reply message from the service.
@@ -29,13 +29,13 @@ type Type struct {
types.Onion
}
func (x *Type) Inner() types.Onion { return x.Onion }
func (x *Type) Insert(o types.Onion) { x.Onion = o }
func (x *Type) Len() int {
func (x *OnionSkin) Inner() types.Onion { return x.Onion }
func (x *OnionSkin) Insert(o types.Onion) { x.Onion = o }
func (x *OnionSkin) Len() int {
return MinLen + x.Onion.Len()
}
func (x *Type) Encode(b slice.Bytes, c *slice.Cursor) {
func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
value := slice.NewUint64()
slice.EncodeUint64(value, x.NBytes)
@@ -45,7 +45,7 @@ func (x *Type) Encode(b slice.Bytes, c *slice.Cursor) {
x.Onion.Encode(b, c)
}
func (x *Type) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
func (x *OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen {
return magicbytes.TooShort(len(b[*c:]), MinLen, string(Magic))
}

View File

@@ -16,35 +16,35 @@ var (
MagicString = "rl"
Magic = slice.Bytes(MagicString)
MinLen = magicbytes.Len + 1 + net.IPv4len
_ types.Onion = &Type{}
_ types.Onion = &OnionSkin{}
)
// Type is reply messages, distinct from forward.Type messages in that the
// OnionSkin is reply messages, distinct from forward.OnionSkin messages in that the
// header encryption uses a different secret than the payload. The magic bytes
// signal this to the relay that receives this, which then looks up the
// PayloadHey matching the To address in the message header. And lastly, each
// step the relay budges up it's message to the front of the packet and puts
// csprng random bytes into the remainder to the same length.
type Type struct {
type OnionSkin struct {
// IP is the address of the next relay in the return leg of a circuit.
net.IP
types.Onion
}
func (x *Type) Inner() types.Onion { return x.Onion }
func (x *Type) Insert(o types.Onion) { x.Onion = o }
func (x *Type) Len() int {
func (x *OnionSkin) Inner() types.Onion { return x.Onion }
func (x *OnionSkin) Insert(o types.Onion) { x.Onion = o }
func (x *OnionSkin) Len() int {
return magicbytes.Len + len(x.IP) + 1 + x.Onion.Len()
}
func (x *Type) Encode(b slice.Bytes, c *slice.Cursor) {
func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
b[*c] = byte(len(x.IP))
copy(b[c.Inc(1):c.Inc(len(x.IP))], x.IP)
x.Onion.Encode(b, c)
}
func (x *Type) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
func (x *OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen {
return magicbytes.TooShort(len(b[*c:]), MinLen, string(Magic))
}

View File

@@ -17,17 +17,17 @@ var (
MagicString = "rs"
Magic = slice.Bytes(MagicString)
MinLen = magicbytes.Len + slice.Uint32Len
_ types.Onion = Response{}
_ types.Onion = OnionSkin{}
)
// Response messages are what are carried back via Reply messages from an Exit.
type Response slice.Bytes
// OnionSkin messages are what are carried back via Reply messages from an Exit.
type OnionSkin slice.Bytes
func (x Response) Inner() types.Onion { return nil }
func (x Response) Insert(_ types.Onion) {}
func (x Response) Len() int { return MinLen + len(x) }
func (x OnionSkin) Inner() types.Onion { return nil }
func (x OnionSkin) Insert(_ types.Onion) {}
func (x OnionSkin) Len() int { return MinLen + len(x) }
func (x Response) Encode(b slice.Bytes, c *slice.Cursor) {
func (x OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
bytesLen := slice.NewUint32()
slice.EncodeUint32(bytesLen, len(x)-slice.Uint32Len)
@@ -35,12 +35,12 @@ func (x Response) Encode(b slice.Bytes, c *slice.Cursor) {
copy(b[*c:c.Inc(len(x))], x)
}
func (x Response) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
func (x OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen {
return magicbytes.TooShort(len(b[*c:]), MinLen, string(Magic))
}
responseLen := slice.DecodeUint32(b[*c:c.Inc(slice.Uint32Len)])
xd := Response(b[*c:c.Inc(responseLen)])
xd := OnionSkin(b[*c:c.Inc(responseLen)])
// replace current slice header using unsafe.
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&x))
hdr.Data = (*reflect.SliceHeader)(unsafe.Pointer(&xd)).Data

View File

@@ -15,10 +15,10 @@ var (
MagicString = "ss"
Magic = slice.Bytes(MagicString)
MinLen = magicbytes.Len + pub.KeyLen*2
_ types.Onion = &Type{}
_ types.Onion = &OnionSkin{}
)
// Type session is a message containing two public keys which identify to a
// OnionSkin session is a message containing two public keys which identify to a
// relay how to decrypt the header in a Reply message, using the HeaderKey, and
// the payload, which uses the PayloadKey. There is two keys in order to prevent
// the Exit node from being able to decrypt the header, but enable it to encrypt
@@ -30,18 +30,18 @@ var (
// in the header, and use the PayloadKey as the public key half with ECDH and
// their generated private key which produces the public key that is placed in
// the header.
type Type struct {
type OnionSkin struct {
HeaderKey, PayloadKey *pub.Key
types.Onion
}
func (x *Type) Inner() types.Onion { return x.Onion }
func (x *Type) Insert(o types.Onion) { x.Onion = o }
func (x *Type) Len() int {
func (x *OnionSkin) Inner() types.Onion { return x.Onion }
func (x *OnionSkin) Insert(o types.Onion) { x.Onion = o }
func (x *OnionSkin) Len() int {
return magicbytes.Len + pub.KeyLen*2 + x.Onion.Len()
}
func (x *Type) Encode(b slice.Bytes, c *slice.Cursor) {
func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
hdr, pld := x.HeaderKey.ToBytes(), x.PayloadKey.ToBytes()
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
copy(b[*c:c.Inc(pub.KeyLen)], hdr[:])
@@ -49,7 +49,7 @@ func (x *Type) Encode(b slice.Bytes, c *slice.Cursor) {
x.Onion.Encode(b, c)
}
func (x *Type) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
func (x *OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen {
return magicbytes.TooShort(len(b[*c:]), MinLen, string(Magic))
}

View File

@@ -15,22 +15,22 @@ var (
MagicString = "tk"
Magic = slice.Bytes(MagicString)
MinLen = magicbytes.Len + sha256.Len
_ types.Onion = Type{}
_ types.Onion = OnionSkin{}
)
// A Type is a 32 byte value.
type Type sha256.Hash
// A OnionSkin is a 32 byte value.
type OnionSkin sha256.Hash
func (x Type) Inner() types.Onion { return nil }
func (x Type) Insert(_ types.Onion) {}
func (x Type) Len() int { return MinLen }
func (x OnionSkin) Inner() types.Onion { return nil }
func (x OnionSkin) Insert(_ types.Onion) {}
func (x OnionSkin) Len() int { return MinLen }
func (x Type) Encode(b slice.Bytes, c *slice.Cursor) {
func (x OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
copy(b[*c:c.Inc(sha256.Len)], x[:])
}
func (x Type) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
func (x OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < MinLen {
return magicbytes.TooShort(len(b[*c:]), MinLen, string(Magic))
}

View File

@@ -10,11 +10,11 @@ var (
// GitRef is the gitref, as in refs/heads/branchname.
GitRef = "refs/heads/main"
// ParentGitCommit is the commit hash of the parent HEAD.
ParentGitCommit = "f687dd36decf1390d2b2f5417f64c1fc98d662b3"
ParentGitCommit = "b5e42be4cb6a99ac6b89ff87d6b54c80002678e6"
// BuildTime stores the time when the current binary was built.
BuildTime = "2022-12-24T10:24:42Z"
BuildTime = "2022-12-24T11:16:03Z"
// SemVer lists the (latest) git tag on the build.
SemVer = "v0.0.225"
SemVer = "v0.0.226"
// PathBase is the path base returned from runtime caller.
PathBase = "/home/loki/src/github.com/Indra-Labs/indra/"
// Major is the major number from the tag.
@@ -22,7 +22,7 @@ var (
// Minor is the minor number from the tag.
Minor = 0
// Patch is the patch version number from the tag.
Patch = 225
Patch = 226
)
// Version returns a pretty printed version information string.