From dfcc21242b0ccfe817e259a9f6faa2ad91b879b9 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 15 Sep 2020 13:47:43 +0300 Subject: [PATCH] [#144] sdk/token: Define session token structure Signed-off-by: Alex Vanin --- pkg/token/session.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pkg/token/session.go diff --git a/pkg/token/session.go b/pkg/token/session.go new file mode 100644 index 00000000..eec6fd32 --- /dev/null +++ b/pkg/token/session.go @@ -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[:] +}