Skip to content

Commit

Permalink
chore: fix int conversion lint (#15070)
Browse files Browse the repository at this point in the history
## 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)
  • Loading branch information
tac0turtle authored Feb 20, 2023
1 parent 067ee92 commit fd34d3f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf
* (x/staking) [#14590](https://github.com/cosmos/cosmos-sdk/pull/14590) `MsgUndelegateResponse` now includes undelegated amount. `x/staking` module's `keeper.Undelegate` now returns 3 values (completionTime,undelegateAmount,error) instead of 2.
* (x/feegrant) [14649](https://github.com/cosmos/cosmos-sdk/pull/14649) Extract Feegrant in its own go.mod and rename the package to `cosmossdk.io/x/feegrant`.
* (x/bank) [#14894](https://github.com/cosmos/cosmos-sdk/pull/14894) Return a human readable denomination for IBC vouchers when querying bank balances. Added a `ResolveDenom` parameter to `types.QueryAllBalancesRequest`.
* (crypto) [#15070](https://github.com/cosmos/cosmos-sdk/pull/15070) `GenerateFromPassword` and `Cost` from `bcrypt.go` now take a `uint32` instead of a `int` type.

### Client Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion crypto/armor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (
// than what they see, which is a significantly cheaper attack then breaking
// a bcrypt hash. (Recall that the nonce still exists to break rainbow tables)
// For further notes on security parameter choice, see README.md
var BcryptSecurityParameter = 12
var BcryptSecurityParameter uint32 = 12

//-----------------------------------------------------------------
// add armor
Expand Down
2 changes: 1 addition & 1 deletion crypto/armor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestUnarmorInfoBytesErrors(t *testing.T) {

func BenchmarkBcryptGenerateFromPassword(b *testing.B) {
passphrase := []byte("passphrase")
for securityParam := 9; securityParam < 16; securityParam++ {
for securityParam := uint32(9); securityParam < 16; securityParam++ {
param := securityParam
b.Run(fmt.Sprintf("benchmark-security-param-%d", param), func(b *testing.B) {
b.ReportAllocs()
Expand Down
24 changes: 12 additions & 12 deletions crypto/keys/bcrypt/bcrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -121,15 +121,15 @@ 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
}
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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -271,19 +271,19 @@ 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
}

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)
}
Expand Down

0 comments on commit fd34d3f

Please sign in to comment.