forked from TrueCloudLab/frostfs-api-go
Implement new request signing mechanism
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
59858805a8
commit
6191903326
9 changed files with 904 additions and 64 deletions
31
util/signature/util.go
Normal file
31
util/signature/util.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package signature
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var bytesPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return make([]byte, 5<<20)
|
||||
},
|
||||
}
|
||||
|
||||
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