Skip to content

Commit dde03e1

Browse files
authored
Ttx/replace random nonce (#1406)
Signed-off-by: Siddhi Khandelwal <siddhi.200727@gmail.com>
1 parent 8ca60c0 commit dde03e1

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/gin-gonic/gin v1.11.0
1414
github.com/go-co-op/gocron/v2 v2.19.1
1515
github.com/google/pprof v0.0.0-20260202012954-cb029daf43ef
16+
github.com/google/uuid v1.6.0
1617
github.com/hashicorp/go-uuid v1.0.3
1718
github.com/hyperledger-labs/fabric-smart-client v0.8.3-0.20260302105910-adde99d4bf54
1819
github.com/hyperledger/fabric-chaincode-go/v2 v2.3.0
@@ -122,7 +123,6 @@ require (
122123
github.com/google/go-cmp v0.7.0 // indirect
123124
github.com/google/gopacket v1.1.19 // indirect
124125
github.com/google/s2a-go v0.1.8 // indirect
125-
github.com/google/uuid v1.6.0 // indirect
126126
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
127127
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
128128
github.com/gorilla/mux v1.8.1 // indirect

token/services/ttx/random.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package ttx
88

99
import (
1010
"crypto/rand"
11+
"io"
1112

1213
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1314
)
@@ -17,12 +18,12 @@ const (
1718
NonceSize = 24
1819
)
1920

20-
// GetRandomBytes returns len random looking bytes
21-
func GetRandomBytes(len int) ([]byte, error) {
22-
key := make([]byte, len)
21+
// GetRandomBytes returns length random bytes, guaranteeing the buffer is fully filled
22+
func GetRandomBytes(length int) ([]byte, error) {
23+
key := make([]byte, length)
2324

24-
// TODO: rand could fill less bytes then len
25-
_, err := rand.Read(key)
25+
// Ensure the buffer is completely filled
26+
_, err := io.ReadFull(rand.Reader, key)
2627
if err != nil {
2728
return nil, errors.Wrap(err, "error getting random bytes")
2829
}

0 commit comments

Comments
 (0)