Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-cid
Commits
b5a08dca
Commit
b5a08dca
authored
Aug 25, 2018
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change EmptyCid to just Nil.
parent
9831436a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
14 deletions
+14
-14
builder.go
builder.go
+2
-2
cid.go
cid.go
+12
-12
No files found.
builder.go
View file @
b5a08dca
...
@@ -36,7 +36,7 @@ func (p Prefix) WithCodec(c uint64) Builder {
...
@@ -36,7 +36,7 @@ func (p Prefix) WithCodec(c uint64) Builder {
func
(
p
V0Builder
)
Sum
(
data
[]
byte
)
(
Cid
,
error
)
{
func
(
p
V0Builder
)
Sum
(
data
[]
byte
)
(
Cid
,
error
)
{
hash
,
err
:=
mh
.
Sum
(
data
,
mh
.
SHA2_256
,
-
1
)
hash
,
err
:=
mh
.
Sum
(
data
,
mh
.
SHA2_256
,
-
1
)
if
err
!=
nil
{
if
err
!=
nil
{
return
EmptyCid
,
err
return
Nil
,
err
}
}
return
NewCidV0
(
hash
),
nil
return
NewCidV0
(
hash
),
nil
}
}
...
@@ -59,7 +59,7 @@ func (p V1Builder) Sum(data []byte) (Cid, error) {
...
@@ -59,7 +59,7 @@ func (p V1Builder) Sum(data []byte) (Cid, error) {
}
}
hash
,
err
:=
mh
.
Sum
(
data
,
p
.
MhType
,
mhLen
)
hash
,
err
:=
mh
.
Sum
(
data
,
p
.
MhType
,
mhLen
)
if
err
!=
nil
{
if
err
!=
nil
{
return
EmptyCid
,
err
return
Nil
,
err
}
}
return
NewCidV1
(
p
.
Codec
,
hash
),
nil
return
NewCidV1
(
p
.
Codec
,
hash
),
nil
}
}
...
...
cid.go
View file @
b5a08dca
...
@@ -161,7 +161,7 @@ func NewCidV1(codecType uint64, mhash mh.Multihash) Cid {
...
@@ -161,7 +161,7 @@ func NewCidV1(codecType uint64, mhash mh.Multihash) Cid {
// - hash mh.Multihash
// - hash mh.Multihash
type
Cid
string
type
Cid
string
var
EmptyCid
=
Cid
(
""
)
var
Nil
=
Cid
(
""
)
// Parse is a short-hand function to perform Decode, Cast etc... on
// Parse is a short-hand function to perform Decode, Cast etc... on
// a generic interface{} type.
// a generic interface{} type.
...
@@ -179,7 +179,7 @@ func Parse(v interface{}) (Cid, error) {
...
@@ -179,7 +179,7 @@ func Parse(v interface{}) (Cid, error) {
case
Cid
:
case
Cid
:
return
v2
,
nil
return
v2
,
nil
default
:
default
:
return
EmptyCid
,
fmt
.
Errorf
(
"can't parse %+v as Cid"
,
v2
)
return
Nil
,
fmt
.
Errorf
(
"can't parse %+v as Cid"
,
v2
)
}
}
}
}
...
@@ -197,13 +197,13 @@ func Parse(v interface{}) (Cid, error) {
...
@@ -197,13 +197,13 @@ func Parse(v interface{}) (Cid, error) {
// as B58-encoded multihashes.
// as B58-encoded multihashes.
func
Decode
(
v
string
)
(
Cid
,
error
)
{
func
Decode
(
v
string
)
(
Cid
,
error
)
{
if
len
(
v
)
<
2
{
if
len
(
v
)
<
2
{
return
EmptyCid
,
ErrCidTooShort
return
Nil
,
ErrCidTooShort
}
}
if
len
(
v
)
==
46
&&
v
[
:
2
]
==
"Qm"
{
if
len
(
v
)
==
46
&&
v
[
:
2
]
==
"Qm"
{
hash
,
err
:=
mh
.
FromB58String
(
v
)
hash
,
err
:=
mh
.
FromB58String
(
v
)
if
err
!=
nil
{
if
err
!=
nil
{
return
EmptyCid
,
err
return
Nil
,
err
}
}
return
NewCidV0
(
hash
),
nil
return
NewCidV0
(
hash
),
nil
...
@@ -211,7 +211,7 @@ func Decode(v string) (Cid, error) {
...
@@ -211,7 +211,7 @@ func Decode(v string) (Cid, error) {
_
,
data
,
err
:=
mbase
.
Decode
(
v
)
_
,
data
,
err
:=
mbase
.
Decode
(
v
)
if
err
!=
nil
{
if
err
!=
nil
{
return
EmptyCid
,
err
return
Nil
,
err
}
}
return
Cast
(
data
)
return
Cast
(
data
)
...
@@ -265,7 +265,7 @@ func Cast(data []byte) (Cid, error) {
...
@@ -265,7 +265,7 @@ func Cast(data []byte) (Cid, error) {
if
len
(
data
)
==
34
&&
data
[
0
]
==
18
&&
data
[
1
]
==
32
{
if
len
(
data
)
==
34
&&
data
[
0
]
==
18
&&
data
[
1
]
==
32
{
h
,
err
:=
mh
.
Cast
(
data
)
h
,
err
:=
mh
.
Cast
(
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
EmptyCid
,
err
return
Nil
,
err
}
}
return
NewCidV0
(
h
),
nil
return
NewCidV0
(
h
),
nil
...
@@ -273,22 +273,22 @@ func Cast(data []byte) (Cid, error) {
...
@@ -273,22 +273,22 @@ func Cast(data []byte) (Cid, error) {
vers
,
n
:=
binary
.
Uvarint
(
data
)
vers
,
n
:=
binary
.
Uvarint
(
data
)
if
err
:=
uvError
(
n
);
err
!=
nil
{
if
err
:=
uvError
(
n
);
err
!=
nil
{
return
EmptyCid
,
err
return
Nil
,
err
}
}
if
vers
!=
1
{
if
vers
!=
1
{
return
EmptyCid
,
fmt
.
Errorf
(
"expected 1 as the cid version number, got: %d"
,
vers
)
return
Nil
,
fmt
.
Errorf
(
"expected 1 as the cid version number, got: %d"
,
vers
)
}
}
_
,
cn
:=
binary
.
Uvarint
(
data
[
n
:
])
_
,
cn
:=
binary
.
Uvarint
(
data
[
n
:
])
if
err
:=
uvError
(
cn
);
err
!=
nil
{
if
err
:=
uvError
(
cn
);
err
!=
nil
{
return
EmptyCid
,
err
return
Nil
,
err
}
}
rest
:=
data
[
n
+
cn
:
]
rest
:=
data
[
n
+
cn
:
]
h
,
err
:=
mh
.
Cast
(
rest
)
h
,
err
:=
mh
.
Cast
(
rest
)
if
err
!=
nil
{
if
err
!=
nil
{
return
EmptyCid
,
err
return
Nil
,
err
}
}
return
Cid
(
data
[
0
:
n
+
cn
+
len
(
h
)]),
nil
return
Cid
(
data
[
0
:
n
+
cn
+
len
(
h
)]),
nil
...
@@ -470,7 +470,7 @@ type Prefix struct {
...
@@ -470,7 +470,7 @@ type Prefix struct {
func
(
p
Prefix
)
Sum
(
data
[]
byte
)
(
Cid
,
error
)
{
func
(
p
Prefix
)
Sum
(
data
[]
byte
)
(
Cid
,
error
)
{
hash
,
err
:=
mh
.
Sum
(
data
,
p
.
MhType
,
p
.
MhLength
)
hash
,
err
:=
mh
.
Sum
(
data
,
p
.
MhType
,
p
.
MhLength
)
if
err
!=
nil
{
if
err
!=
nil
{
return
EmptyCid
,
err
return
Nil
,
err
}
}
switch
p
.
Version
{
switch
p
.
Version
{
...
@@ -479,7 +479,7 @@ func (p Prefix) Sum(data []byte) (Cid, error) {
...
@@ -479,7 +479,7 @@ func (p Prefix) Sum(data []byte) (Cid, error) {
case
1
:
case
1
:
return
NewCidV1
(
p
.
Codec
,
hash
),
nil
return
NewCidV1
(
p
.
Codec
,
hash
),
nil
default
:
default
:
return
EmptyCid
,
fmt
.
Errorf
(
"invalid cid version"
)
return
Nil
,
fmt
.
Errorf
(
"invalid cid version"
)
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment