2023-06-06 06:29:23 +00:00
|
|
|
package tree
|
|
|
|
|
|
|
|
import (
|
2024-07-11 14:18:28 +00:00
|
|
|
frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
|
|
|
|
tree "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool/tree/service"
|
2023-06-06 06:29:23 +00:00
|
|
|
)
|
|
|
|
|
2024-07-11 14:18:28 +00:00
|
|
|
type message interface {
|
|
|
|
SignedDataSize() int
|
|
|
|
ReadSignedData([]byte) ([]byte, error)
|
|
|
|
GetSignature() *tree.Signature
|
2024-11-07 11:29:55 +00:00
|
|
|
SetSignature(*tree.Signature) error
|
2024-07-11 14:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2023-06-06 06:29:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-07-11 14:18:28 +00:00
|
|
|
keySDK := frostfsecdsa.Signer(p.key.PrivateKey)
|
|
|
|
data, err := keySDK.Sign(binBody)
|
2023-06-06 06:29:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-07-11 14:18:28 +00:00
|
|
|
rawPub := make([]byte, keySDK.Public().MaxEncodedSize())
|
|
|
|
rawPub = rawPub[:keySDK.Public().Encode(rawPub)]
|
2024-11-07 11:29:55 +00:00
|
|
|
return m.SetSignature(&tree.Signature{
|
2024-07-11 14:18:28 +00:00
|
|
|
Key: rawPub,
|
|
|
|
Sign: data,
|
|
|
|
})
|
2023-06-06 06:29:23 +00:00
|
|
|
}
|