-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
48 lines (41 loc) · 887 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package ipldswh
import (
"github.com/ipfs/go-cid"
"github.com/ipld/go-ipld-prime"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
mc "github.com/multiformats/go-multicodec"
mh "github.com/multiformats/go-multihash"
)
func gitShaToCid(sha []byte) cid.Cid {
h, _ := mh.Encode(sha, mh.SHA1)
return cid.NewCidV1(cid.GitRaw, h)
}
func swh1SnpShaToCid(sha []byte) cid.Cid {
h, _ := mh.Encode(sha, mh.SHA1)
return cid.NewCidV1((uint64)(mc.Swhid1Snp), h)
}
func cidToSha(c cid.Cid) []byte {
h := c.Hash()
return h[len(h)-20:]
}
func sha(l ipld.Link) []byte {
cl, ok := l.(cidlink.Link)
if !ok {
return nil
}
return cidToSha(cl.Cid)
}
func (l Link) sha() []byte {
cl, ok := l.x.(cidlink.Link)
if !ok {
return nil
}
return cidToSha(cl.Cid)
}
func (l Snapshot_Link) sha() []byte {
cl, ok := l.x.(cidlink.Link)
if !ok {
return nil
}
return cidToSha(cl.Cid)
}