Unverified Commit f538ddd4 authored by Eric Myhre's avatar Eric Myhre Committed by GitHub

Merge pull request #23 from ipld/bugs/cbor-link-traversal

fix(encoding): match go-ipld-cbor cid encoding
parents 27a6b503 015389d5
......@@ -127,7 +127,7 @@ func Marshal(n ipld.Node, sink shared.TokenSink) error {
switch lnk := v.(type) {
case cidlink.Link:
tk.Type = tok.TBytes
tk.Bytes = lnk.Bytes()
tk.Bytes = append([]byte{0}, lnk.Bytes()...)
tk.Tagged = true
tk.Tag = linkTag
_, err = sink.Step(&tk)
......
package dagcbor
import (
"errors"
"fmt"
"math"
......@@ -12,6 +13,10 @@ import (
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
)
var (
ErrInvalidMultibase = errors.New("invalid multibase on IPLD link")
)
// This should be identical to the general feature in the parent package,
// except for the `case tok.TBytes` block,
// which has dag-cbor's special sauce for detecting schemafree links.
......@@ -126,7 +131,10 @@ func unmarshal(nb ipld.NodeBuilder, tokSrc shared.TokenSource, tk *tok.Token) (i
}
switch tk.Tag {
case linkTag:
elCid, err := cid.Cast(tk.Bytes)
if tk.Bytes[0] != 0 {
return nil, ErrInvalidMultibase
}
elCid, err := cid.Cast(tk.Bytes[1:])
if err != nil {
return nil, err
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment