chore: fix int conversion lint (#15070)

## Description

this pr fixes a integer conversion lint issue. 

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
Marko
2023-02-20 12:36:51 +00:00
committed by GitHub
parent 067ee92d4d
commit fd34d3f221
4 changed files with 15 additions and 14 deletions
+12 -12
View File
@@ -18,9 +18,9 @@ import (
)
const (
MinCost int = 4 // the minimum allowable cost as passed in to GenerateFromPassword
MaxCost int = 31 // the maximum allowable cost as passed in to GenerateFromPassword
DefaultCost int = 10 // the cost that will actually be set if a cost below MinCost is passed into GenerateFromPassword
MinCost uint32 = 4 // the minimum allowable cost as passed in to GenerateFromPassword
MaxCost uint32 = 31 // the maximum allowable cost as passed in to GenerateFromPassword
DefaultCost uint32 = 10 // the cost that will actually be set if a cost below MinCost is passed into GenerateFromPassword
)
// ErrMismatchedHashAndPassword is returned from CompareHashAndPassword when a password and hash do
@@ -76,7 +76,7 @@ var magicCipherData = []byte{
type hashed struct {
hash []byte
salt []byte
cost int // allowed range is MinCost to MaxCost
cost uint32 // allowed range is MinCost to MaxCost
major byte
minor byte
}
@@ -85,7 +85,7 @@ type hashed struct {
// cost. If the cost given is less than MinCost, the cost will be set to
// DefaultCost, instead. Use CompareHashAndPassword, as defined in this package,
// to compare the returned hashed password with its cleartext version.
func GenerateFromPassword(salt []byte, password []byte, cost int) ([]byte, error) {
func GenerateFromPassword(salt []byte, password []byte, cost uint32) ([]byte, error) {
if len(salt) != maxSaltSize {
return nil, fmt.Errorf("salt len must be %v", maxSaltSize)
}
@@ -121,7 +121,7 @@ func CompareHashAndPassword(hashedPassword, password []byte) error {
// password. When, in the future, the hashing cost of a password system needs
// to be increased in order to adjust for greater computational power, this
// function allows one to establish which passwords need to be updated.
func Cost(hashedPassword []byte) (int, error) {
func Cost(hashedPassword []byte) (uint32, error) {
p, err := newFromHash(hashedPassword)
if err != nil {
return 0, err
@@ -129,7 +129,7 @@ func Cost(hashedPassword []byte) (int, error) {
return p.cost, nil
}
func newFromPassword(salt []byte, password []byte, cost int) (*hashed, error) {
func newFromPassword(salt []byte, password []byte, cost uint32) (*hashed, error) {
if cost < MinCost {
cost = DefaultCost
}
@@ -180,11 +180,11 @@ func newFromHash(hashedSecret []byte) (*hashed, error) {
return p, nil
}
func bcrypt(password []byte, cost int, salt []byte) ([]byte, error) {
func bcrypt(password []byte, cost uint32, salt []byte) ([]byte, error) {
cipherData := make([]byte, len(magicCipherData))
copy(cipherData, magicCipherData)
c, err := expensiveBlowfishSetup(password, uint32(cost), salt)
c, err := expensiveBlowfishSetup(password, cost, salt)
if err != nil {
return nil, err
}
@@ -271,11 +271,11 @@ func (p *hashed) decodeCost(sbytes []byte) (int, error) {
if err != nil {
return -1, err
}
err = checkCost(cost)
err = checkCost(uint32(cost))
if err != nil {
return -1, err
}
p.cost = cost
p.cost = uint32(cost)
return 3, nil
}
@@ -283,7 +283,7 @@ func (p *hashed) String() string {
return fmt.Sprintf("&{hash: %#v, salt: %#v, cost: %d, major: %c, minor: %c}", string(p.hash), p.salt, p.cost, p.major, p.minor)
}
func checkCost(cost int) error {
func checkCost(cost uint32) error {
if cost < MinCost || cost > MaxCost {
return InvalidCostError(cost)
}