frostfs-api-go/pkg/container/id/test/id.go
Leonard Lyubich 7314038069 [#283] pkg/container: Define ID in a separate package
In order to prevent potential cross imports, container ID should be defined
in a separate package as a base type. A similar approach was used in the
NeoFS API design.

Create `pkg/container/id` package and replace container ID implementation to
it. Related API in `container` package is deprecated from now.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-26 12:24:58 +03:00

26 lines
466 B
Go

package cidtest
import (
"crypto/sha256"
"math/rand"
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
)
// Generate returns random cid.ID.
func Generate() *cid.ID {
checksum := [sha256.Size]byte{}
rand.Read(checksum[:])
return GenerateWithChecksum(checksum)
}
// GenerateWithChecksum returns cid.ID initialized
// with specified checksum.
func GenerateWithChecksum(cs [sha256.Size]byte) *cid.ID {
id := cid.New()
id.SetSHA256(cs)
return id
}