forked from TrueCloudLab/frostfs-sdk-go
Denis Kirillov
7c06cdff2d
Update tree service to fix split tree problem. Tree intermediate nodes can be duplicated so we must handle this. Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
38 lines
929 B
Go
38 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)
|
|
}
|
|
|
|
// 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)]
|
|
m.SetSignature(&tree.Signature{
|
|
Key: rawPub,
|
|
Sign: data,
|
|
})
|
|
|
|
return nil
|
|
}
|