Compare commits
4 Commits
gx/v0.7.18
...
gx/v0.7.20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
078355866b | ||
|
|
1805dd530f | ||
|
|
2055d2e652 | ||
|
|
63d4b33fcf |
@@ -1 +1 @@
|
||||
0.7.18: QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ
|
||||
0.7.20: QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY
|
||||
|
||||
21
cid.go
21
cid.go
@@ -144,6 +144,27 @@ func NewCidV1(codecType uint64, mhash mh.Multihash) *Cid {
|
||||
}
|
||||
}
|
||||
|
||||
// NewPrefixV0 returns a CIDv0 prefix with the specified multihash type.
|
||||
func NewPrefixV0(mhType uint64) Prefix {
|
||||
return Prefix{
|
||||
MhType: mhType,
|
||||
MhLength: mh.DefaultLengths[mhType],
|
||||
Version: 0,
|
||||
Codec: DagProtobuf,
|
||||
}
|
||||
}
|
||||
|
||||
// NewPrefixV1 returns a CIDv1 prefix with the specified codec and multihash
|
||||
// type.
|
||||
func NewPrefixV1(codecType uint64, mhType uint64) Prefix {
|
||||
return Prefix{
|
||||
MhType: mhType,
|
||||
MhLength: mh.DefaultLengths[mhType],
|
||||
Version: 1,
|
||||
Codec: codecType,
|
||||
}
|
||||
}
|
||||
|
||||
// Cid represents a self-describing content adressed
|
||||
// identifier. It is formed by a Version, a Codec (which indicates
|
||||
// a multicodec-packed content type) and a Multihash.
|
||||
|
||||
58
cid_test.go
58
cid_test.go
@@ -189,6 +189,64 @@ func TestV0ErrorCases(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewPrefixV1(t *testing.T) {
|
||||
data := []byte("this is some test content")
|
||||
|
||||
// Construct c1
|
||||
prefix := NewPrefixV1(DagCBOR, mh.SHA2_256)
|
||||
c1, err := prefix.Sum(data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if c1.Prefix() != prefix {
|
||||
t.Fatal("prefix not preserved")
|
||||
}
|
||||
|
||||
// Construct c2
|
||||
hash, err := mh.Sum(data, mh.SHA2_256, -1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c2 := NewCidV1(DagCBOR, hash)
|
||||
|
||||
if !c1.Equals(c2) {
|
||||
t.Fatal("cids mismatch")
|
||||
}
|
||||
if c1.Prefix() != c2.Prefix() {
|
||||
t.Fatal("prefixes mismatch")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewPrefixV0(t *testing.T) {
|
||||
data := []byte("this is some test content")
|
||||
|
||||
// Construct c1
|
||||
prefix := NewPrefixV0(mh.SHA2_256)
|
||||
c1, err := prefix.Sum(data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if c1.Prefix() != prefix {
|
||||
t.Fatal("prefix not preserved")
|
||||
}
|
||||
|
||||
// Construct c2
|
||||
hash, err := mh.Sum(data, mh.SHA2_256, -1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c2 := NewCidV0(hash)
|
||||
|
||||
if !c1.Equals(c2) {
|
||||
t.Fatal("cids mismatch")
|
||||
}
|
||||
if c1.Prefix() != c2.Prefix() {
|
||||
t.Fatal("prefixes mismatch")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrefixRoundtrip(t *testing.T) {
|
||||
data := []byte("this is some test content")
|
||||
hash, _ := mh.Sum(data, mh.SHA2_256, -1)
|
||||
|
||||
10
package.json
10
package.json
@@ -9,15 +9,15 @@
|
||||
"gxDependencies": [
|
||||
{
|
||||
"author": "whyrusleeping",
|
||||
"hash": "QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P",
|
||||
"hash": "QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua",
|
||||
"name": "go-multihash",
|
||||
"version": "1.0.5"
|
||||
"version": "1.0.7"
|
||||
},
|
||||
{
|
||||
"author": "whyrusleeping",
|
||||
"hash": "QmafgXF3u3QSWErQoZ2URmQp5PFG384htoE7J338nS2H7T",
|
||||
"hash": "QmexBtiTTEwwn42Yi6ouKt6VqzpA6wjJgiW1oh9VfaRrup",
|
||||
"name": "go-multibase",
|
||||
"version": "0.2.5"
|
||||
"version": "0.2.6"
|
||||
}
|
||||
],
|
||||
"gxVersion": "0.8.0",
|
||||
@@ -25,6 +25,6 @@
|
||||
"license": "MIT",
|
||||
"name": "go-cid",
|
||||
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
|
||||
"version": "0.7.18"
|
||||
"version": "0.7.20"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user