frostfs-sdk-go/container/id/test/id.go
Evgenii Stratonikov 49ad985cad [#161] *: Do not use math/rand.Read()
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-09-08 17:17:02 +03:00

26 lines
448 B
Go

package cidtest
import (
"crypto/rand"
"crypto/sha256"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
)
// ID returns random cid.ID.
func ID() cid.ID {
checksum := [sha256.Size]byte{}
_, _ = rand.Read(checksum[:])
return IDWithChecksum(checksum)
}
// IDWithChecksum returns cid.ID initialized
// with specified checksum.
func IDWithChecksum(cs [sha256.Size]byte) cid.ID {
var id cid.ID
id.SetSHA256(cs)
return id
}