Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak parameters of NewPrefix functions. #51

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cid.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,24 @@ 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,
}
}

// 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,
}
Expand Down
4 changes: 2 additions & 2 deletions cid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down