Skip to content

Commit

Permalink
Dhash api (#177)
Browse files Browse the repository at this point in the history
* Remove unused error return form dhash API
  • Loading branch information
gammazero authored Mar 29, 2024
1 parent 57f6c46 commit 62073e5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
6 changes: 4 additions & 2 deletions dhash/dhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ func sha256Multiple(dest []byte, payloads ...[]byte) []byte {

// SecondMultihash calculates SHA256 over the multihash and wraps it into
// another multihash with DBL_SHA256 codec.
func SecondMultihash(mh multihash.Multihash) (multihash.Multihash, error) {
func SecondMultihash(mh multihash.Multihash) multihash.Multihash {
digest := SHA256(append(secondHashPrefix, mh...), nil)
return multihash.Encode(digest, multihash.DBL_SHA2_256)
// The error return from multihash.Encode is legacy; it is always nil.
mh2, _ := multihash.Encode(digest, multihash.DBL_SHA2_256)
return mh2
}

// deriveKey derives encryptioin key from the passphrase using SHA256
Expand Down
3 changes: 1 addition & 2 deletions dhash/dhash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func TestCanDecryptEncryptedValue(t *testing.T) {

func TestSecondMultihash(t *testing.T) {
mh := test.RandomMultihashes(1)[0]
smh, err := SecondMultihash(mh)
require.NoError(t, err)
smh := SecondMultihash(mh)

h := sha256.New()
h.Write(append(secondHashPrefix, mh...))
Expand Down
7 changes: 1 addition & 6 deletions find/client/dhash_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ func (c *DHashClient) Find(ctx context.Context, mh multihash.Multihash) (*model.
func (c *DHashClient) FindAsync(ctx context.Context, mh multihash.Multihash, resChan chan<- model.ProviderResult) error {
defer close(resChan)

dhmh, err := dhash.SecondMultihash(mh)
if err != nil {
return err
}

encryptedMultihashResults, err := c.dhstoreAPI.FindMultihash(ctx, dhmh)
encryptedMultihashResults, err := c.dhstoreAPI.FindMultihash(ctx, dhash.SecondMultihash(mh))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/ipfs/go-ipld-format v0.6.0
github.com/ipfs/go-log/v2 v2.5.1
github.com/ipld/go-ipld-prime v0.21.0
github.com/libp2p/go-libp2p v0.33.1
github.com/libp2p/go-libp2p v0.33.2
github.com/libp2p/go-libp2p-pubsub v0.10.0
github.com/libp2p/go-msgio v0.3.0
github.com/mr-tron/base58 v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6
github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg=
github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM=
github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro=
github.com/libp2p/go-libp2p v0.33.1 h1:tvJl9b9M6nSLBtZSXSguq+/lRhRj2oLRkyhBmQNMFLA=
github.com/libp2p/go-libp2p v0.33.1/go.mod h1:zOUTMjG4I7TXwMndNyOBn/CNtVBLlvBlnxfi+8xzx+E=
github.com/libp2p/go-libp2p v0.33.2 h1:vCdwnFxoGOXMKmaGHlDSnL4bM3fQeW8pgIa9DECnb40=
github.com/libp2p/go-libp2p v0.33.2/go.mod h1:zTeppLuCvUIkT118pFVzA8xzP/p2dJYOMApCkFh0Yww=
github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94=
github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8=
github.com/libp2p/go-libp2p-pubsub v0.10.0 h1:wS0S5FlISavMaAbxyQn3dxMOe2eegMfswM471RuHJwA=
Expand Down

0 comments on commit 62073e5

Please sign in to comment.