frostfs-api-go/session/service.go
Leonard Lyubich dfc2dd8a78 session: replace PToken structure with PrivateToken interface
In previous implementation PToken contained the full Token structure.
Since private token is used for data signature only, storing unused
fields of a user token is impractical. To emphasize the purpose of
the private part of the session, it makes sense to provide the user
of the session package with its interface. The interface will only provide
the functionality of data signing with private session key.

This commit:

  * removes PToken structure from session package;

  * defines PrivateToken interface of private session part;

  * adds the implementation of PrivateToken on unexported struct;

  * provides the constructor that generates session key internally.
2020-04-29 11:52:05 +03:00

47 lines
1.2 KiB
Go

package session
import (
"context"
"crypto/ecdsa"
"github.com/nspcc-dev/neofs-api-go/refs"
)
type (
// KeyStore is an interface that describes storage,
// that allows to fetch public keys by OwnerID.
KeyStore interface {
Get(ctx context.Context, id refs.OwnerID) ([]*ecdsa.PublicKey, error)
}
// TokenStore is a PToken storage manipulation interface.
TokenStore interface {
// New returns new token with specified parameters.
New(p TokenParams) PrivateToken
// Fetch tries to fetch a token with specified id.
Fetch(id TokenID) PrivateToken
// Remove removes token with id from store.
Remove(id TokenID)
}
// TokenParams contains params to create new PToken.
TokenParams struct {
FirstEpoch uint64
LastEpoch uint64
Address Address
OwnerID OwnerID
Verb Verb
}
)
// NewInitRequest returns new initialization CreateRequest from passed Token.
func NewInitRequest(t *Token) *CreateRequest {
return &CreateRequest{Message: &CreateRequest_Init{Init: t}}
}
// NewSignedRequest returns new signed CreateRequest from passed Token.
func NewSignedRequest(t *Token) *CreateRequest {
return &CreateRequest{Message: &CreateRequest_Signed{Signed: t}}
}