2021-10-26 13:19:11 +00:00
|
|
|
package cidtest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha256"
|
|
|
|
"math/rand"
|
|
|
|
|
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
)
|
|
|
|
|
2021-11-12 11:19:16 +00:00
|
|
|
// ID returns random cid.ID.
|
|
|
|
func ID() *cid.ID {
|
2021-10-26 13:19:11 +00:00
|
|
|
checksum := [sha256.Size]byte{}
|
|
|
|
|
|
|
|
rand.Read(checksum[:])
|
|
|
|
|
2021-11-12 11:19:16 +00:00
|
|
|
return IDWithChecksum(checksum)
|
2021-10-26 13:19:11 +00:00
|
|
|
}
|
|
|
|
|
2021-11-12 11:19:16 +00:00
|
|
|
// IDWithChecksum returns cid.ID initialized
|
2021-10-26 13:19:11 +00:00
|
|
|
// with specified checksum.
|
2021-11-12 11:19:16 +00:00
|
|
|
func IDWithChecksum(cs [sha256.Size]byte) *cid.ID {
|
2021-10-26 13:19:11 +00:00
|
|
|
id := cid.New()
|
|
|
|
id.SetSHA256(cs)
|
|
|
|
|
|
|
|
return id
|
|
|
|
}
|