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.
This commit is contained in:
Leonard Lyubich 2020-04-29 11:52:05 +03:00
parent 1e86e1112a
commit dfc2dd8a78
5 changed files with 90 additions and 28 deletions

View file

@ -13,7 +13,7 @@ import (
type simpleStore struct {
*sync.RWMutex
tokens map[TokenID]*PToken
tokens map[TokenID]PrivateToken
}
// TODO get curve from neofs-crypto
@ -25,12 +25,12 @@ func defaultCurve() elliptic.Curve {
func NewSimpleStore() TokenStore {
return &simpleStore{
RWMutex: new(sync.RWMutex),
tokens: make(map[TokenID]*PToken),
tokens: make(map[TokenID]PrivateToken),
}
}
// New returns new token with specified parameters.
func (s *simpleStore) New(p TokenParams) *PToken {
func (s *simpleStore) New(p TokenParams) PrivateToken {
tid, err := refs.NewUUID()
if err != nil {
return nil
@ -54,10 +54,8 @@ func (s *simpleStore) New(p TokenParams) *PToken {
token.SetExpirationEpoch(p.LastEpoch)
token.SetSessionKey(crypto.MarshalPublicKey(&key.PublicKey))
t := &PToken{
mtx: new(sync.Mutex),
Token: *token,
PrivateKey: key,
t := &pToken{
sessionKey: key,
}
s.Lock()
@ -68,7 +66,7 @@ func (s *simpleStore) New(p TokenParams) *PToken {
}
// Fetch tries to fetch a token with specified id.
func (s *simpleStore) Fetch(id TokenID) *PToken {
func (s *simpleStore) Fetch(id TokenID) PrivateToken {
s.RLock()
defer s.RUnlock()