From 00ce980d82a95b0c50e27ff354710ce1e9912021 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 16 Nov 2020 17:58:07 +0300 Subject: [PATCH] [#199] sdk/token: Correct linter's remarks Signed-off-by: Leonard Lyubich --- pkg/token/bearer.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/token/bearer.go b/pkg/token/bearer.go index 6dbb457..812faf2 100644 --- a/pkg/token/bearer.go +++ b/pkg/token/bearer.go @@ -13,6 +13,12 @@ import ( crypto "github.com/nspcc-dev/neofs-crypto" ) +var ( + errNilBearerToken = errors.New("bearer token is not set") + errNilBearerTokenBody = errors.New("bearer token body is not set") + errNilBearerTokenEACL = errors.New("bearer token EACL table is not set") +) + type BearerToken struct { token acl.BearerToken } @@ -63,6 +69,7 @@ func (b *BearerToken) SignToken(key *ecdsa.PrivateKey) error { } signWrapper := v2signature.StableMarshalerWrapper{SM: b.token.GetBody()} + return signature.SignDataWithHandler(key, signWrapper, func(key []byte, sig []byte) { bearerSignature := new(refs.Signature) bearerSignature.SetKey(key) @@ -103,15 +110,15 @@ func NewBearerTokenFromV2(v2 *acl.BearerToken) *BearerToken { } } -// sanityCheck if bearer token is ready to be issued +// sanityCheck if bearer token is ready to be issued. func sanityCheck(b *BearerToken) error { switch { case b == nil: - return errors.New("bearer token is not set") + return errNilBearerToken case b.token.GetBody() == nil: - return errors.New("bearer token body is not set") + return errNilBearerTokenBody case b.token.GetBody().GetEACL() == nil: - return errors.New("bearer token EACL table is not set") + return errNilBearerTokenEACL } // consider checking EACL sanity there, lifetime correctness, etc.