format repo with "gofumpt" tool

This commit is contained in:
Tnze
2022-11-26 20:37:57 +08:00
parent 7814e7b1ab
commit fad92fe364
61 changed files with 333 additions and 268 deletions

View File

@ -28,7 +28,7 @@ const verifyTokenLen = 16
// Encrypt a connection, with authentication
func Encrypt(conn *net.Conn, name string, profilePubKey *rsa.PublicKey) (*Resp, error) {
//generate keys
// generate keys
key, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {
return nil, err
@ -39,30 +39,30 @@ func Encrypt(conn *net.Conn, name string, profilePubKey *rsa.PublicKey) (*Resp,
return nil, err
}
//encryption request
// encryption request
nonce, err := encryptionRequest(conn, publicKey)
if err != nil {
return nil, err
}
//encryption response
// encryption response
SharedSecret, err := encryptionResponse(conn, profilePubKey, nonce, key)
if err != nil {
return nil, err
}
//encryption the connection
// encryption the connection
block, err := aes.NewCipher(SharedSecret)
if err != nil {
return nil, errors.New("load aes encryption key fail")
}
conn.SetCipher( //启用加密
conn.SetCipher( // 启用加密
CFB8.NewCFB8Encrypt(block, SharedSecret),
CFB8.NewCFB8Decrypt(block, SharedSecret),
)
hash := authDigest("", SharedSecret, publicKey)
resp, err := authentication(name, hash) //auth
resp, err := authentication(name, hash) // auth
if err != nil {
return nil, errors.New("auth servers down")
}
@ -136,7 +136,7 @@ func encryptionResponse(conn *net.Conn, profilePubKey *rsa.PublicKey, nonce []by
}
}
//confirm to verify token
// confirm to verify token
SharedSecret, err := rsa.DecryptPKCS1v15(rand.Reader, key, ESharedSecret)
if err != nil {
return nil, err

View File

@ -15,17 +15,17 @@ func TestResp(t *testing.T) {
}
wantID := uuid.Must(uuid.Parse("853c80ef3c3749fdaa49938b674adae6"))
//check UUID
// check UUID
if resp.ID != wantID {
t.Errorf("uuid doesn't match: %v, want %s", resp.ID, wantID)
}
//check name
// check name
if resp.Name != "jeb_" {
t.Errorf("name doesn't match: %s, want %s", resp.Name, "jeb_")
}
//check texture
// check texture
texture, err := resp.Texture()
if err != nil {
t.Fatal(err)