mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-04 15:58:13 +08:00
Reverts the changes that allowed small keys (ed25519 keys) to be inlined. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package coredag
|
|
|
|
import (
|
|
"io"
|
|
"io/ioutil"
|
|
"math"
|
|
|
|
"gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
|
|
|
|
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
|
|
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
|
|
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
|
|
)
|
|
|
|
func dagpbJSONParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
|
|
data, err := ioutil.ReadAll(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
nd := &merkledag.ProtoNode{}
|
|
|
|
err = nd.UnmarshalJSON(data)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
nd.SetCidBuilder(cidPrefix(mhType, mhLen))
|
|
|
|
return []ipld.Node{nd}, nil
|
|
}
|
|
|
|
func dagpbRawParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
|
|
data, err := ioutil.ReadAll(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
nd, err := merkledag.DecodeProtobuf(data)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
nd.SetCidBuilder(cidPrefix(mhType, mhLen))
|
|
|
|
return []ipld.Node{nd}, nil
|
|
}
|
|
|
|
func cidPrefix(mhType uint64, mhLen int) *cid.Prefix {
|
|
if mhType == math.MaxUint64 {
|
|
mhType = mh.SHA2_256
|
|
}
|
|
|
|
prefix := &cid.Prefix{
|
|
MhType: mhType,
|
|
MhLength: mhLen,
|
|
Version: 1,
|
|
Codec: cid.DagProtobuf,
|
|
}
|
|
|
|
if mhType == mh.SHA2_256 {
|
|
prefix.Version = 0
|
|
}
|
|
|
|
return prefix
|
|
}
|