first key exchange thing
This commit is contained in:
@@ -2,22 +2,18 @@ package game
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Name string
|
||||
PublicKey ed25519.PublicKey
|
||||
PrivateKey ed25519.PrivateKey
|
||||
Name string
|
||||
PublicKey ed25519.PublicKey
|
||||
}
|
||||
|
||||
func NewUser(name string) User {
|
||||
func NewUser(name string, publicKey ed25519.PublicKey) User {
|
||||
// ed25519
|
||||
|
||||
public, private, _ := ed25519.GenerateKey(rand.Reader)
|
||||
return User{
|
||||
Name: name,
|
||||
PublicKey: public,
|
||||
PrivateKey: private,
|
||||
Name: name,
|
||||
PublicKey: publicKey,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package rest_handler
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"net/http"
|
||||
|
||||
"gitea.elara.ws/Hazel/hangman/internal/game"
|
||||
@@ -11,7 +12,8 @@ func CreateUser(c echo.Context) error {
|
||||
session := game.GetSession(c.Param("session"))
|
||||
|
||||
type BodyContent struct {
|
||||
Name string
|
||||
Name string
|
||||
PublicKey string
|
||||
}
|
||||
var bodyContent BodyContent
|
||||
|
||||
@@ -20,7 +22,9 @@ func CreateUser(c echo.Context) error {
|
||||
return c.String(http.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
user := game.NewUser(bodyContent.Name)
|
||||
pub, _ := base64.StdEncoding.DecodeString(bodyContent.PublicKey)
|
||||
user := game.NewUser(bodyContent.Name, pub)
|
||||
session.AddUser(user)
|
||||
|
||||
return c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user