Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
move error
Browse files Browse the repository at this point in the history
  • Loading branch information
dvaumoron committed Jan 16, 2024
1 parent 3307f8a commit e98d887
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 0 additions & 2 deletions pkg/apierrors/apierrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ package apierrors
import "errors"

var (
ErrCheck = errors.New("invalid checksum")
ErrNoAsset = errors.New("asset not found for current platform")
ErrNoSum = errors.New("file checksum not found for current platform")
ErrReturn = errors.New("unexpected value returned by API")
)
10 changes: 7 additions & 3 deletions pkg/check/sha256/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import (
"bytes"
"crypto/sha256"
"encoding/hex"
"errors"
"strings"
)

"github.com/dvaumoron/gotofuenv/pkg/apierrors"
var (
errCheck = errors.New("invalid sha256 checksum")
errNoSum = errors.New("file sha256 checksum not found for current platform")
)

func Check(data []byte, dataSum []byte) error {
hashed := sha256.Sum256(data)
if !bytes.Equal(dataSum, hashed[:]) {
return apierrors.ErrCheck
return errCheck
}
return nil
}
Expand All @@ -26,5 +30,5 @@ func Extract(dataSums []byte, fileName string) ([]byte, error) {
return hex.DecodeString(dataSumStr)
}
}
return nil, apierrors.ErrNoSum
return nil, errNoSum
}

0 comments on commit e98d887

Please sign in to comment.