Token test passing
This commit is contained in:
@@ -95,7 +95,7 @@ func PeelOnion(b slice.Bytes, c *slice.Cursor) (on types.Onion, e error) {
|
||||
}
|
||||
on = &o
|
||||
case token.MagicString:
|
||||
var o token.OnionSkin
|
||||
o := token.NewOnionSkin()
|
||||
if e = o.Decode(b, c); check(e) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/Indra-Labs/indra/pkg/wire/exit"
|
||||
"github.com/Indra-Labs/indra/pkg/wire/forward"
|
||||
"github.com/Indra-Labs/indra/pkg/wire/reply"
|
||||
"github.com/Indra-Labs/indra/pkg/wire/token"
|
||||
log2 "github.com/cybriq/proc/pkg/log"
|
||||
)
|
||||
|
||||
@@ -250,7 +251,30 @@ func TestOnionSkins_Session(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOnionSkins_Token(t *testing.T) {
|
||||
|
||||
log2.CodeLoc = true
|
||||
var e error
|
||||
ni := nonce.NewID()
|
||||
n := sha256.Single(ni[:])
|
||||
on := OnionSkins{}.
|
||||
Token(n).
|
||||
Assemble()
|
||||
onb := EncodeOnion(on)
|
||||
c := slice.NewCursor()
|
||||
var oncn types.Onion
|
||||
if oncn, e = PeelOnion(onb, c); check(e) {
|
||||
t.FailNow()
|
||||
}
|
||||
var cf *token.OnionSkin
|
||||
var ok bool
|
||||
if cf, ok = oncn.(*token.OnionSkin); !ok {
|
||||
t.Error("did not unwrap expected type", reflect.TypeOf(oncn))
|
||||
t.FailNow()
|
||||
}
|
||||
if sha256.Hash(*cf) != n {
|
||||
log.I.S(n, cf)
|
||||
t.Error("confirmation ID did not unwrap correctly")
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func GetTwoPrvKeys(t *testing.T) (prv1, prv2 *prv.Key) {
|
||||
|
||||
@@ -93,7 +93,7 @@ func (o OnionSkins) Session(fwd, rtn *pub.Key) OnionSkins {
|
||||
})
|
||||
}
|
||||
func (o OnionSkins) Token(tok sha256.Hash) OnionSkins {
|
||||
return append(o, token.OnionSkin(tok))
|
||||
return append(o, (*token.OnionSkin)(&tok))
|
||||
}
|
||||
|
||||
// Assemble inserts the slice of OnionSkin s inside each other so the first then
|
||||
|
||||
@@ -15,25 +15,31 @@ var (
|
||||
MagicString = "tk"
|
||||
Magic = slice.Bytes(MagicString)
|
||||
MinLen = magicbytes.Len + sha256.Len
|
||||
_ types.Onion = OnionSkin{}
|
||||
_ types.Onion = &OnionSkin{}
|
||||
)
|
||||
|
||||
// A OnionSkin is a 32 byte value.
|
||||
type OnionSkin sha256.Hash
|
||||
|
||||
func (x OnionSkin) Inner() types.Onion { return nil }
|
||||
func (x OnionSkin) Insert(_ types.Onion) {}
|
||||
func (x OnionSkin) Len() int { return MinLen }
|
||||
|
||||
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 NewOnionSkin() *OnionSkin {
|
||||
var os sha256.Hash
|
||||
return (*OnionSkin)(&os)
|
||||
}
|
||||
|
||||
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))
|
||||
func (x *OnionSkin) Inner() types.Onion { return nil }
|
||||
func (x *OnionSkin) Insert(_ types.Onion) {}
|
||||
func (x *OnionSkin) Len() int { return MinLen }
|
||||
|
||||
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[:sha256.Len])
|
||||
}
|
||||
|
||||
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[:], b[c.Inc(magicbytes.Len):c.Inc(sha256.Len)])
|
||||
copy(x[:], b[*c:c.Inc(sha256.Len)])
|
||||
return
|
||||
}
|
||||
|
||||
@@ -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 = "d99cde172a75abd19b48386a59a79197f7f6596e"
|
||||
ParentGitCommit = "d4fb691e4463bd06a95211947d5062af43d820f8"
|
||||
// BuildTime stores the time when the current binary was built.
|
||||
BuildTime = "2022-12-24T14:40:18Z"
|
||||
BuildTime = "2022-12-24T15:41:35Z"
|
||||
// SemVer lists the (latest) git tag on the build.
|
||||
SemVer = "v0.0.231"
|
||||
SemVer = "v0.0.232"
|
||||
// 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 = 231
|
||||
Patch = 232
|
||||
)
|
||||
|
||||
// Version returns a pretty printed version information string.
|
||||
|
||||
Reference in New Issue
Block a user