forked from TrueCloudLab/frostfs-api-go
service: change constant errors
This commit: * moves defined errors to a separate file; * renames ErrEmptyToken to ErrNilToken; * merges ErrZeroTTL and ErrIncorrectTTL into single ErrInvalidTTL.
This commit is contained in:
parent
e3cab218dc
commit
fc177c4ce3
6 changed files with 31 additions and 37 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"encoding/binary"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/internal"
|
||||
"github.com/nspcc-dev/neofs-api-go/refs"
|
||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||
)
|
||||
|
@ -62,9 +61,6 @@ type SessionToken interface {
|
|||
SignatureContainer
|
||||
}
|
||||
|
||||
// ErrEmptyToken is raised when passed Token is nil.
|
||||
const ErrEmptyToken = internal.Error("token is empty")
|
||||
|
||||
var _ SessionToken = (*Token)(nil)
|
||||
|
||||
var tokenEndianness = binary.BigEndian
|
||||
|
@ -183,11 +179,11 @@ func verificationTokenData(token SessionToken) []byte {
|
|||
|
||||
// SignToken calculates and stores the signature of token information.
|
||||
//
|
||||
// If passed token is nil, ErrEmptyToken returns.
|
||||
// If passed token is nil, ErrNilToken returns.
|
||||
// If passed private key is nil, crypto.ErrEmptyPrivateKey returns.
|
||||
func SignToken(token SessionToken, key *ecdsa.PrivateKey) error {
|
||||
if token == nil {
|
||||
return ErrEmptyToken
|
||||
return ErrNilToken
|
||||
} else if key == nil {
|
||||
return crypto.ErrEmptyPrivateKey
|
||||
}
|
||||
|
@ -204,11 +200,11 @@ func SignToken(token SessionToken, key *ecdsa.PrivateKey) error {
|
|||
|
||||
// VerifyTokenSignature checks if token was signed correctly.
|
||||
//
|
||||
// If passed token is nil, ErrEmptyToken returns.
|
||||
// If passed token is nil, ErrNilToken returns.
|
||||
// If passed public key is nil, crypto.ErrEmptyPublicKey returns.
|
||||
func VerifyTokenSignature(token SessionToken, key *ecdsa.PublicKey) error {
|
||||
if token == nil {
|
||||
return ErrEmptyToken
|
||||
return ErrNilToken
|
||||
} else if key == nil {
|
||||
return crypto.ErrEmptyPublicKey
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue