forked from TrueCloudLab/frostfs-api-go
[#144] sdk/token: Define session token structure
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
0b9ddd10f8
commit
dfcc21242b
1 changed files with 35 additions and 0 deletions
35
pkg/token/session.go
Normal file
35
pkg/token/session.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package token
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type SessionToken struct {
|
||||
id uuid.UUID
|
||||
pubKey []byte
|
||||
}
|
||||
|
||||
func CreateSessionToken(id, pub []byte) (*SessionToken, error) {
|
||||
var tokenID uuid.UUID
|
||||
|
||||
err := tokenID.UnmarshalBinary(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
key := make([]byte, len(pub))
|
||||
copy(key[:], pub)
|
||||
|
||||
return &SessionToken{
|
||||
id: tokenID,
|
||||
pubKey: key,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s SessionToken) SessionKey() []byte {
|
||||
return s.pubKey
|
||||
}
|
||||
|
||||
func (s SessionToken) ID() []byte {
|
||||
return s.id[:]
|
||||
}
|
Loading…
Reference in a new issue