Skip to content

Commit

Permalink
fix: updating the way we're comparing hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
WendelHime committed Oct 9, 2024
1 parent b2fee93 commit 88f63ee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion water/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var ErrFailedToVerifyHashSum = errors.New("failed to verify hash sum")

func (d *downloader) verifyHashSum(data []byte) error {
sha256Hashsum := sha256.Sum256(data)
if d.expectedHashSum == "" || !bytes.Equal(sha256Hashsum[:], []byte(d.expectedHashSum)) {
if d.expectedHashSum == "" || d.expectedHashSum != fmt.Sprintf("%x", sha256Hashsum[:]) {
return ErrFailedToVerifyHashSum
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion water/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/sha256"
"fmt"
"io"
"net/http"
"testing"
Expand Down Expand Up @@ -73,7 +74,7 @@ func TestDownloadWASM(t *testing.T) {

contentMessage := "content"
hashsum := sha256.Sum256([]byte(contentMessage))
contentHashsum := string(hashsum[:])
contentHashsum := fmt.Sprintf("%x", hashsum[:])
var tests = []struct {
name string
givenHTTPClient *http.Client
Expand Down

0 comments on commit 88f63ee

Please sign in to comment.