frostfs-sdk-go/util/signature/util.go
Evgenii Stratonikov 1feafcbcbf [#53] util: move signature package from neofs-api-go
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2021-11-08 12:39:45 +03:00

31 lines
514 B
Go

package signature
import (
"errors"
"sync"
)
var bytesPool = sync.Pool{
New: func() interface{} {
b := make([]byte, 5<<20)
return &b
},
}
func dataForSignature(src DataSource) ([]byte, error) {
if src == nil {
return nil, errors.New("nil source")
}
buf := *bytesPool.Get().(*[]byte)
if size := src.SignedDataSize(); size < 0 {
return nil, errors.New("negative length")
} else if size <= cap(buf) {
buf = buf[:size]
} else {
buf = make([]byte, size)
}
return src.ReadSignedData(buf)
}