frostfs-sdk-go/object/id/test/generate.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

37 lines
670 B
Go

package oidtest
import (
"crypto/rand"
"crypto/sha256"
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
)
// ID returns random oid.ID.
func ID() oid.ID {
checksum := [sha256.Size]byte{}
_, _ = rand.Read(checksum[:])
return idWithChecksum(checksum)
}
// idWithChecksum returns oid.ID initialized
// with specified checksum.
func idWithChecksum(cs [sha256.Size]byte) oid.ID {
var id oid.ID
id.SetSHA256(cs)
return id
}
// Address returns random oid.Address.
func Address() oid.Address {
var x oid.Address
x.SetContainer(cidtest.ID())
x.SetObject(ID())
return x
}