lotus/storage/sbmock/util.go

37 lines
591 B
Go
Raw Normal View History

2020-01-13 20:47:27 +00:00
package sbmock
import (
2020-01-14 01:24:04 +00:00
"bytes"
2020-01-13 20:47:27 +00:00
"crypto/rand"
"io"
"io/ioutil"
2020-01-14 01:24:04 +00:00
"github.com/filecoin-project/specs-actors/actors/abi"
2020-01-14 01:24:04 +00:00
"github.com/filecoin-project/go-sectorbuilder"
2020-01-13 20:47:27 +00:00
)
func randB(n uint64) []byte {
b, err := ioutil.ReadAll(io.LimitReader(rand.Reader, int64(n)))
if err != nil {
panic(err)
}
return b
}
func commDR(in []byte) (out [32]byte) {
for i, b := range in {
out[i] = ^b
}
return out
}
func commD(b []byte) [32]byte {
c, err := sectorbuilder.GeneratePieceCommitment(bytes.NewReader(b), abi.UnpaddedPieceSize(len(b)))
2020-01-14 01:24:04 +00:00
if err != nil {
panic(err)
}
return c
2020-01-13 20:47:27 +00:00
}