forked from TrueCloudLab/frostfs-api-go
service: call OwnerKey setter in AddSignKey method implementation
This commit is contained in:
parent
22af538c98
commit
bd261cf566
2 changed files with 33 additions and 2 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"io"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/refs"
|
||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||
)
|
||||
|
||||
type signAccumWithToken struct {
|
||||
|
@ -125,10 +126,14 @@ func (x Token_Info_Verb) Bytes() []byte {
|
|||
return data
|
||||
}
|
||||
|
||||
// AddSignKey calls a Signature field setter of token with passed signature.
|
||||
func (s signedSessionToken) AddSignKey(sig []byte, _ *ecdsa.PublicKey) {
|
||||
// AddSignKey calls a Signature field setter and an OwnerKey field setter with corresponding arguments.
|
||||
func (s signedSessionToken) AddSignKey(sig []byte, key *ecdsa.PublicKey) {
|
||||
if s.SessionToken != nil {
|
||||
s.SessionToken.SetSignature(sig)
|
||||
|
||||
s.SessionToken.SetOwnerKey(
|
||||
crypto.MarshalPublicKey(key),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/refs"
|
||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||
"github.com/nspcc-dev/neofs-crypto/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -220,3 +221,28 @@ func TestSignToken(t *testing.T) {
|
|||
require.NoError(t, VerifySignatureWithKey(pk, verifiedToken))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSignedSessionToken_AddSignKey(t *testing.T) {
|
||||
// nil SessionToken
|
||||
s := new(signedSessionToken)
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
s.AddSignKey(nil, nil)
|
||||
})
|
||||
|
||||
// create test public key and signature
|
||||
pk := &test.DecodeKey(0).PublicKey
|
||||
sig := []byte{1, 2, 3}
|
||||
|
||||
s.SessionToken = new(Token)
|
||||
|
||||
// add key-signature pair to SessionToken
|
||||
s.AddSignKey(sig, pk)
|
||||
|
||||
require.Equal(t, sig, s.GetSignature())
|
||||
|
||||
require.Equal(t,
|
||||
crypto.MarshalPublicKey(pk),
|
||||
s.GetOwnerKey(),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue