[#58] object: Allow to set marshal data

Now it is possible set marshaled data to reduce memory
allocations.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-10-06 15:05:30 +03:00
parent 309aa4ac78
commit f50872f1bc
5 changed files with 94 additions and 4 deletions

View file

@ -35,8 +35,10 @@ func SignDataWithHandler(key *ecdsa.PrivateKey, src DataSource, handler KeySigna
opts[i](cfg)
}
buffer := newBufferFromPool(src.SignedDataSize())
defer returnBufferToPool(buffer)
buffer, ok := tryGetNewBufferFromPool(src.SignedDataSize())
if ok {
defer returnBufferToPool(buffer)
}
data, err := src.ReadSignedData(buffer.data)
if err != nil {
@ -64,8 +66,10 @@ func VerifyDataWithSource(dataSrc DataSource, sigSrc KeySignatureSource, opts ..
opts[i](cfg)
}
buffer := newBufferFromPool(dataSrc.SignedDataSize())
defer returnBufferToPool(buffer)
buffer, ok := tryGetNewBufferFromPool(dataSrc.SignedDataSize())
if ok {
defer returnBufferToPool(buffer)
}
data, err := dataSrc.ReadSignedData(buffer.data)
if err != nil {