2019-11-18 13:34:06 +00:00
|
|
|
package session
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
|
2020-03-31 07:05:26 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/refs"
|
2019-11-18 13:34:06 +00:00
|
|
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
|
|
|
)
|
|
|
|
|
|
|
|
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) *PToken
|
|
|
|
|
|
|
|
// Fetch tries to fetch a token with specified id.
|
|
|
|
Fetch(id TokenID) *PToken
|
|
|
|
|
|
|
|
// Remove removes token with id from store.
|
|
|
|
Remove(id TokenID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TokenParams contains params to create new PToken.
|
|
|
|
TokenParams struct {
|
|
|
|
FirstEpoch uint64
|
|
|
|
LastEpoch uint64
|
|
|
|
ObjectID []ObjectID
|
|
|
|
OwnerID OwnerID
|
2020-01-17 11:56:51 +00:00
|
|
|
PublicKeys [][]byte
|
2019-11-18 13:34:06 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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}}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sign signs contents of the header with the private key.
|
|
|
|
func (m *VerificationHeader) Sign(key *ecdsa.PrivateKey) error {
|
|
|
|
s, err := crypto.Sign(key, m.PublicKey)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.KeySignature = s
|
|
|
|
return nil
|
|
|
|
}
|