frostfs-sdk-go/pool/tree/pool_signature.go
Nikita Zinkevich 4a9a3572fa
All checks were successful
DCO / DCO (pull_request) Successful in 1m4s
Tests and linters / Tests (pull_request) Successful in 1m24s
Tests and linters / Lint (pull_request) Successful in 2m5s
[#185] Implement rpc/client for tree service
Signed-off-by: Nikita Zinkevich <n.zinkevich@yadro.com>
2024-11-20 16:57:20 +03:00

36 lines
929 B
Go

package tree
import (
frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
tree "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool/tree/service"
)
type message interface {
SignedDataSize() int
ReadSignedData([]byte) ([]byte, error)
GetSignature() *tree.Signature
SetSignature(*tree.Signature) error
}
// signMessage uses the pool key and signs any protobuf
// message that was generated for the TreeService by the
// protoc-gen-go-frostfs generator. Returns any errors directly.
func (p *Pool) signRequest(m message) error {
binBody, err := m.ReadSignedData(nil)
if err != nil {
return err
}
keySDK := frostfsecdsa.Signer(p.key.PrivateKey)
data, err := keySDK.Sign(binBody)
if err != nil {
return err
}
rawPub := make([]byte, keySDK.Public().MaxEncodedSize())
rawPub = rawPub[:keySDK.Public().Encode(rawPub)]
return m.SetSignature(&tree.Signature{
Key: rawPub,
Sign: data,
})
}