MONOREPO
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package bot
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type SecureChatSession struct {
|
||||
Account *Account
|
||||
PlayerKeys PlayerKeys
|
||||
Private *rsa.PrivateKey
|
||||
SessionId uuid.UUID
|
||||
}
|
||||
|
||||
func NewSecureChat(a *Account) (s *SecureChatSession, err error) {
|
||||
s = &SecureChatSession{Account: a}
|
||||
s.PlayerKeys, err = a.FetchKeys()
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
block, _ := pem.Decode([]byte(s.PlayerKeys.KeyPair.PrivateKey))
|
||||
|
||||
k, err := x509.ParsePKCS8PrivateKey(block.Bytes)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
s.Private = k.(*rsa.PrivateKey)
|
||||
|
||||
s.SessionId, err = uuid.NewRandom()
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user