Compare commits

..

7 Commits

Author SHA1 Message Date
Jeromy
177ab398cc gx publish 0.7.3 2016-10-24 17:31:04 -07:00
Jeromy
02ce4e9b23 fix decoding of empty strings 2016-10-24 17:30:53 -07:00
Jeromy
460554fb6e gx publish 0.7.2 2016-10-24 09:16:05 -07:00
Jeromy
5d17ab8c70 add bitcoin tx value 2016-10-24 09:10:06 -07:00
Jeromy
ed8d621d9a gx publish 0.7.0 2016-10-19 17:54:06 -07:00
Jeromy
9a43493ca7 add codes for bitcoin and ethereum 2016-10-19 17:53:39 -07:00
Jeromy
8677934d48 add small test to fuzz cid creation routines 2016-10-09 12:19:14 -07:00
4 changed files with 30 additions and 4 deletions

View File

@@ -1 +1 @@
0.6.0: QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z
0.7.3: QmXfiyr2RWEXpVDdaYnD2HNiBk6UBddsvEP4RPfXb6nGqY

9
cid.go
View File

@@ -16,6 +16,11 @@ const (
CBOR = 0x71
Raw = 0x72
JSON = 0x73
EthereumBlock = 0x90
EthereumTx = 0x91
BitcoinBlock = 0xb0
BitcoinTx = 0xb1
)
func NewCidV0(h mh.Multihash) *Cid {
@@ -41,6 +46,10 @@ type Cid struct {
}
func Decode(v string) (*Cid, error) {
if len(v) < 2 {
return nil, fmt.Errorf("cid too short")
}
if len(v) == 46 && v[:2] == "Qm" {
hash, err := mh.FromB58String(v)
if err != nil {

View File

@@ -2,6 +2,7 @@ package cid
import (
"bytes"
"math/rand"
"testing"
mh "github.com/multiformats/go-multihash"
@@ -51,6 +52,13 @@ func TestBasicMarshaling(t *testing.T) {
assertEqual(t, cid, out2)
}
func TestEmptyString(t *testing.T) {
_, err := Decode("")
if err == nil {
t.Fatal("shouldnt be able to parse an empty cid")
}
}
func TestV0Handling(t *testing.T) {
old := "QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"
@@ -108,3 +116,12 @@ func TestPrefixRoundtrip(t *testing.T) {
t.Fatal("input prefix didnt match output")
}
}
func TestFuzzCid(t *testing.T) {
buf := make([]byte, 128)
for i := 0; i < 200; i++ {
s := rand.Intn(128)
rand.Read(buf[:s])
_, _ = Cast(buf[:s])
}
}

View File

@@ -15,9 +15,9 @@
},
{
"author": "whyrusleeping",
"hash": "QmYiTi9mKBMjfiup7na7PhJK7QEZPdMTJenLdgFYVQ2NUv",
"hash": "QmUq3H9YpcPphbRj6ct6rBgBE377A8wANP8zPMRqe1WYbf",
"name": "go-multibase",
"version": "0.2.0"
"version": "0.2.1"
}
],
"gxVersion": "0.8.0",
@@ -25,6 +25,6 @@
"license": "",
"name": "go-cid",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "0.6.0"
"version": "0.7.3"
}