forked from TrueCloudLab/frostfs-sdk-go
[#150] signature: Add scheme
Allow `SignOption` to set 2 parameters: 1. Default signature scheme, which is used in case scheme is unspecified. 2. Restrict scheme option which also checks that scheme is either unspecified or equal to the restricted scheme. This is only used for verification and is necessary because some of the signatures are used in smart-contracts. Also provide signature struct to sign/verify functions in helpers. The constant names differ a bit from those in API because of linter complaints. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
4fba1af6aa
commit
1c7dd03cf5
8 changed files with 129 additions and 131 deletions
|
@ -7,6 +7,16 @@ import (
|
|||
// Signature represents v2-compatible signature.
|
||||
type Signature refs.Signature
|
||||
|
||||
// Scheme represents signature scheme.
|
||||
type Scheme uint32
|
||||
|
||||
// Supported signature schemes.
|
||||
const (
|
||||
Unspecified Scheme = iota
|
||||
ECDSAWithSHA512
|
||||
RFC6979WithSHA256
|
||||
)
|
||||
|
||||
// NewFromV2 wraps v2 Signature message to Signature.
|
||||
//
|
||||
// Nil refs.Signature converts to nil.
|
||||
|
@ -43,6 +53,16 @@ func (s *Signature) SetSign(v []byte) {
|
|||
(*refs.Signature)(s).SetSign(v)
|
||||
}
|
||||
|
||||
// Scheme returns signature scheme.
|
||||
func (s *Signature) Scheme() Scheme {
|
||||
return Scheme((*refs.Signature)(s).GetScheme())
|
||||
}
|
||||
|
||||
// SetScheme sets signature scheme.
|
||||
func (s *Signature) SetScheme(v Scheme) {
|
||||
(*refs.Signature)(s).SetScheme(refs.SignatureScheme(v))
|
||||
}
|
||||
|
||||
// ToV2 converts Signature to v2 Signature message.
|
||||
//
|
||||
// Nil Signature converts to nil.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue