[#190] crypto: Start Scheme enum from zero

Enumerate signature schemes of `Scheme` type from 0 in order to sync
with NeoFS API protocol by values.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
remotes/fyrchik/split-info-format
Leonard Lyubich 2022-04-19 10:25:42 +03:00 committed by LeL
parent ea043f4ca3
commit 2f9cc50fec
2 changed files with 5 additions and 10 deletions

View File

@ -48,12 +48,7 @@ func (x *Signature) Calculate(signer Signer, data []byte) error {
m := (*refs.Signature)(x)
scheme := refs.SignatureScheme(signer.Scheme())
if scheme > 0 {
scheme-- // to sync numeric values
}
m.SetScheme(scheme)
m.SetScheme(refs.SignatureScheme(signer.Scheme()))
m.SetSign(signature)
m.SetKey(key)
@ -69,7 +64,7 @@ func (x *Signature) Calculate(signer Signer, data []byte) error {
func (x Signature) Verify(data []byte) bool {
m := (*refs.Signature)(&x)
f, ok := publicKeys[Scheme(m.GetScheme()+1)] // increment to sync numeric values
f, ok := publicKeys[Scheme(m.GetScheme())]
if !ok {
return false
}

View File

@ -6,12 +6,12 @@ import (
// Scheme represents digital signature algorithm with fixed cryptographic hash function.
//
// Non-positive values are reserved and depend on context (e.g. unsupported scheme).
type Scheme uint32
// Negative values are reserved and depend on context (e.g. unsupported scheme).
type Scheme int32
//nolint:revive
const (
_ Scheme = iota
_ Scheme = iota - 1
ECDSA_SHA512 // ECDSA with SHA-512 hashing (FIPS 186-3)
ECDSA_DETERMINISTIC_SHA256 // Deterministic ECDSA with SHA-256 hashing (RFC 6979)