2021-05-24 17:34:56 +00:00
|
|
|
package sessiontest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/session"
|
|
|
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
|
|
|
"github.com/nspcc-dev/neofs-crypto/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Generate returns random session.Token.
|
2021-05-28 08:00:46 +00:00
|
|
|
//
|
|
|
|
// Resulting token is unsigned.
|
2021-05-24 17:34:56 +00:00
|
|
|
func Generate() *session.Token {
|
|
|
|
tok := session.NewToken()
|
|
|
|
|
|
|
|
uid, err := uuid.New().MarshalBinary()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
w := new(owner.NEO3Wallet)
|
|
|
|
rand.Read(w.Bytes())
|
|
|
|
|
|
|
|
ownerID := owner.NewID()
|
|
|
|
ownerID.SetNeo3Wallet(w)
|
|
|
|
|
|
|
|
keyBin := crypto.MarshalPublicKey(&test.DecodeKey(0).PublicKey)
|
|
|
|
|
|
|
|
tok.SetID(uid)
|
|
|
|
tok.SetOwnerID(ownerID)
|
|
|
|
tok.SetSessionKey(keyBin)
|
|
|
|
|
|
|
|
return tok
|
|
|
|
}
|
2021-05-28 08:00:46 +00:00
|
|
|
|
|
|
|
// GenerateSigned returns signed random session.Token.
|
|
|
|
//
|
|
|
|
// Panics if token could not be signed (actually unexpected).
|
|
|
|
func GenerateSigned() *session.Token {
|
|
|
|
tok := Generate()
|
|
|
|
|
|
|
|
err := tok.Sign(test.DecodeKey(0))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return tok
|
|
|
|
}
|