2021-10-26 13:19:11 +00:00
|
|
|
package cidtest
|
|
|
|
|
|
|
|
import (
|
2023-09-08 14:15:08 +00:00
|
|
|
"crypto/rand"
|
2021-10-26 13:19:11 +00:00
|
|
|
"crypto/sha256"
|
|
|
|
|
2023-03-07 11:20:03 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2021-10-26 13:19:11 +00:00
|
|
|
)
|
|
|
|
|
2021-11-12 11:19:16 +00:00
|
|
|
// ID returns random cid.ID.
|
2022-04-11 16:25:14 +00:00
|
|
|
func ID() cid.ID {
|
2021-10-26 13:19:11 +00:00
|
|
|
checksum := [sha256.Size]byte{}
|
|
|
|
|
2023-09-08 14:15:08 +00:00
|
|
|
_, _ = rand.Read(checksum[:])
|
2021-10-26 13:19:11 +00:00
|
|
|
|
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.
|
2022-04-11 16:25:14 +00:00
|
|
|
func IDWithChecksum(cs [sha256.Size]byte) cid.ID {
|
|
|
|
var id cid.ID
|
2021-10-26 13:19:11 +00:00
|
|
|
id.SetSHA256(cs)
|
|
|
|
|
|
|
|
return id
|
|
|
|
}
|