mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
(no commit message provided)
This commit is contained in:
committed by
Prad Nukala (aider)
parent
5fd43dfd6b
commit
2f976209db
@@ -1,22 +0,0 @@
|
||||
package random
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
// GetRandomBytes randomly generates n bytes.
|
||||
func GetRandomBytes(n uint32) []byte {
|
||||
buf := make([]byte, n)
|
||||
_, err := rand.Read(buf)
|
||||
if err != nil {
|
||||
panic(err) // out of randomness, should never happen
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
// GetRandomUint32 randomly generates an unsigned 32-bit integer.
|
||||
func GetRandomUint32() uint32 {
|
||||
b := GetRandomBytes(4)
|
||||
return binary.BigEndian.Uint32(b)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package random_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/onsonr/hway/crypto/subtle/random"
|
||||
)
|
||||
|
||||
func TestGetRandomBytes(t *testing.T) {
|
||||
for i := 0; i <= 32; i++ {
|
||||
buf := random.GetRandomBytes(uint32(i))
|
||||
if len(buf) != i {
|
||||
t.Errorf("length of the output doesn't match the input")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user