7314038069
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>
26 lines
466 B
Go
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
|
|
}
|