Skip to content

Commit

Permalink
package upgrade (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
chandra1-n authored Dec 3, 2024
1 parent 1c29fd5 commit dcd818d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

## 1.199.3 (December, 03 2024)
ENHANCEMENTS:
* Updated crypto/rand package instead of math/rand as part of penetration testing.

## 1.199.2 (November, 26 2024)
BUG FIXES:
* resource/spotinst_ocean_gke_import: Fixed update of attribute `min_size` and `max_size`.
Expand Down
31 changes: 28 additions & 3 deletions spotinst/commons/common_spotinst_resource.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
package commons

import (
"crypto/rand"
"encoding/json"
"fmt"
"log"
"math/rand"
"time"
"math/big"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// GenerateSecureRandomInt generates a secure random integer between min and max using crypto/rand
func GenerateSecureRandomInt(min, max int64) (int64, error) {
if min >= max {
return 0, fmt.Errorf("invalid range: min must be less than max")
}

// Calculate the range
rangeSize := max - min + 1

// Generate a secure random number in the range 0 to rangeSize-1
nBig, err := rand.Int(rand.Reader, big.NewInt(rangeSize))
if err != nil {
return 0, err
}

// Add the min to shift the range to min...max
return nBig.Int64() + min, nil
}

func init() {
rand.Seed(time.Now().UnixNano())
// Example usage of GenerateSecureRandomInt within init
randomNumber, err := GenerateSecureRandomInt(1, 100)
if err != nil {
log.Fatalf("Failed to generate secure random number: %v", err)
}
log.Printf("Secure random number: %d", randomNumber)

// Remove timestamp from provider logger, use the timestamp from the Terraform logger.
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))
Expand Down

0 comments on commit dcd818d

Please sign in to comment.