2020-09-10 13:10:33 +00:00
|
|
|
package pkg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Signature represents v2-compatible signature.
|
|
|
|
type Signature refs.Signature
|
|
|
|
|
|
|
|
// NewSignatureFromV2 wraps v2 Signature message to Signature.
|
2021-06-08 18:12:17 +00:00
|
|
|
//
|
|
|
|
// Nil refs.Signature converts to nil.
|
2020-09-10 13:10:33 +00:00
|
|
|
func NewSignatureFromV2(sV2 *refs.Signature) *Signature {
|
|
|
|
return (*Signature)(sV2)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSignature creates and initializes blank Signature.
|
|
|
|
//
|
|
|
|
// Works similar as NewSignatureFromV2(new(Signature)).
|
|
|
|
func NewSignature() *Signature {
|
|
|
|
return NewSignatureFromV2(new(refs.Signature))
|
|
|
|
}
|
|
|
|
|
2020-11-16 08:19:03 +00:00
|
|
|
// Key sets binary public key.
|
|
|
|
func (s *Signature) Key() []byte {
|
2020-09-10 13:10:33 +00:00
|
|
|
return (*refs.Signature)(s).GetKey()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetKey returns binary public key.
|
|
|
|
func (s *Signature) SetKey(v []byte) {
|
|
|
|
(*refs.Signature)(s).SetKey(v)
|
|
|
|
}
|
|
|
|
|
2020-11-16 08:19:03 +00:00
|
|
|
// Sign return signature value.
|
|
|
|
func (s *Signature) Sign() []byte {
|
2020-09-10 13:10:33 +00:00
|
|
|
return (*refs.Signature)(s).GetSign()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetSign sets signature value.
|
|
|
|
func (s *Signature) SetSign(v []byte) {
|
|
|
|
(*refs.Signature)(s).SetSign(v)
|
|
|
|
}
|
|
|
|
|
2021-06-08 18:12:17 +00:00
|
|
|
// ToV2 converts Signature to v2 Signature message.
|
|
|
|
//
|
|
|
|
// Nil Signature converts to nil.
|
2020-09-10 13:10:33 +00:00
|
|
|
func (s *Signature) ToV2() *refs.Signature {
|
|
|
|
return (*refs.Signature)(s)
|
|
|
|
}
|
2020-11-13 13:23:41 +00:00
|
|
|
|
|
|
|
// Marshal marshals Signature into a protobuf binary form.
|
|
|
|
//
|
|
|
|
// Buffer is allocated when the argument is empty.
|
|
|
|
// Otherwise, the first buffer is used.
|
|
|
|
func (s *Signature) Marshal(b ...[]byte) ([]byte, error) {
|
|
|
|
var buf []byte
|
|
|
|
if len(b) > 0 {
|
|
|
|
buf = b[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
return (*refs.Signature)(s).
|
|
|
|
StableMarshal(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal unmarshals protobuf binary representation of Signature.
|
|
|
|
func (s *Signature) Unmarshal(data []byte) error {
|
|
|
|
return (*refs.Signature)(s).
|
|
|
|
Unmarshal(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalJSON encodes Signature to protobuf JSON format.
|
|
|
|
func (s *Signature) MarshalJSON() ([]byte, error) {
|
|
|
|
return (*refs.Signature)(s).
|
|
|
|
MarshalJSON()
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON decodes Signature from protobuf JSON format.
|
|
|
|
func (s *Signature) UnmarshalJSON(data []byte) error {
|
|
|
|
return (*refs.Signature)(s).
|
|
|
|
UnmarshalJSON(data)
|
|
|
|
}
|