diff --git a/cid.go b/cid.go index 99a26a6..0366080 100644 --- a/cid.go +++ b/cid.go @@ -145,10 +145,10 @@ func NewCidV1(codecType uint64, mhash mh.Multihash) *Cid { } // NewPrefixV0 returns a CIDv0 prefix with the specified multihash type. -func NewPrefixV0(mhType uint64) Prefix { +func NewPrefixV0() Prefix { return Prefix{ - MhType: mhType, - MhLength: mh.DefaultLengths[mhType], + MhType: mh.SHA2_256, + MhLength: mh.DefaultLengths[mh.SHA2_256], Version: 0, Codec: DagProtobuf, } @@ -156,10 +156,13 @@ func NewPrefixV0(mhType uint64) Prefix { // NewPrefixV1 returns a CIDv1 prefix with the specified codec and multihash // type. -func NewPrefixV1(codecType uint64, mhType uint64) Prefix { +func NewPrefixV1(codecType uint64, mhType uint64, mhLen int) Prefix { + if mhLen == -1 { + mhLen = mh.DefaultLengths[mhType] + } return Prefix{ MhType: mhType, - MhLength: mh.DefaultLengths[mhType], + MhLength: mhLen, Version: 1, Codec: codecType, } diff --git a/cid_test.go b/cid_test.go index b7bdd89..e035b57 100644 --- a/cid_test.go +++ b/cid_test.go @@ -193,7 +193,7 @@ func TestNewPrefixV1(t *testing.T) { data := []byte("this is some test content") // Construct c1 - prefix := NewPrefixV1(DagCBOR, mh.SHA2_256) + prefix := NewPrefixV1(DagCBOR, mh.SHA2_256, -1) c1, err := prefix.Sum(data) if err != nil { t.Fatal(err) @@ -222,7 +222,7 @@ func TestNewPrefixV0(t *testing.T) { data := []byte("this is some test content") // Construct c1 - prefix := NewPrefixV0(mh.SHA2_256) + prefix := NewPrefixV0() c1, err := prefix.Sum(data) if err != nil { t.Fatal(err)