forked from TrueCloudLab/frostfs-sdk-go
[#53] util: move signature package from neofs-api-go
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
bd554c94d8
commit
1feafcbcbf
3 changed files with 242 additions and 0 deletions
31
util/signature/util.go
Normal file
31
util/signature/util.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue