mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-03 18:47:41 +08:00
all: bump go 1.20
This commit is contained in:
parent
4b6eff7c64
commit
f33123fcf6
2
.github/workflows/go.yml
vendored
2
.github/workflows/go.yml
vendored
@ -16,7 +16,7 @@ jobs:
|
||||
- name: Set up Go 1.x
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.19
|
||||
go-version: 1.20
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v2
|
||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
||||
module github.com/Mrs4s/MiraiGo
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d
|
||||
|
@ -1,6 +1,9 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"crypto/ecdh"
|
||||
"crypto/md5"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
@ -51,3 +54,15 @@ func (e *ECDH) FetchPubKey(uin int64) {
|
||||
key, _ := hex.DecodeString(pubKey.Meta.PubKey)
|
||||
e.init(key) // todo check key sign
|
||||
}
|
||||
|
||||
func (e *ECDH) init(svrPubKey []byte) {
|
||||
p256 := ecdh.P256()
|
||||
local, _ := p256.GenerateKey(rand.Reader)
|
||||
remote, _ := p256.NewPublicKey(svrPubKey)
|
||||
share, _ := local.ECDH(remote)
|
||||
|
||||
hash := md5.New()
|
||||
hash.Write(share[:16])
|
||||
e.ShareKey = hash.Sum(nil)
|
||||
e.PublicKey = local.PublicKey().Bytes()
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
//go:build !go1.20
|
||||
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"crypto/elliptic"
|
||||
"crypto/md5"
|
||||
"crypto/rand"
|
||||
)
|
||||
|
||||
func (e *ECDH) init(svrPubKey []byte) {
|
||||
p256 := elliptic.P256()
|
||||
key, sx, sy, _ := elliptic.GenerateKey(p256, rand.Reader)
|
||||
tx, ty := elliptic.Unmarshal(p256, svrPubKey)
|
||||
x, _ := p256.ScalarMult(tx, ty, key)
|
||||
hash := md5.Sum(x.Bytes()[:16])
|
||||
e.ShareKey = hash[:]
|
||||
e.PublicKey = elliptic.Marshal(p256, sx, sy)
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
//go:build go1.20
|
||||
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"crypto/ecdh"
|
||||
"crypto/md5"
|
||||
"crypto/rand"
|
||||
)
|
||||
|
||||
func (e *ECDH) init(svrPubKey []byte) {
|
||||
p256 := ecdh.P256()
|
||||
local, _ := p256.GenerateKey(rand.Reader)
|
||||
remote, _ := p256.NewPublicKey(svrPubKey)
|
||||
share, _ := local.ECDH(remote)
|
||||
|
||||
hash := md5.New()
|
||||
hash.Write(share[:16])
|
||||
e.ShareKey = hash.Sum(nil)
|
||||
e.PublicKey = local.PublicKey().Bytes()
|
||||
}
|
@ -2,7 +2,6 @@ package utils
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
@ -50,10 +49,8 @@ func ConvertSubVersionToInt(str string) int32 {
|
||||
}
|
||||
|
||||
// B2S converts byte slice to a string without memory allocation.
|
||||
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
|
||||
// from github.com/savsgio/gotils/strconv
|
||||
func B2S(b []byte) string {
|
||||
return *(*string)(unsafe.Pointer(&b))
|
||||
return unsafe.String(&b[0], len(b))
|
||||
}
|
||||
|
||||
// S2B converts string to a byte slice without memory allocation.
|
||||
@ -61,12 +58,7 @@ func B2S(b []byte) string {
|
||||
// Note it may break if string and/or slice header will change
|
||||
// in the future go versions.
|
||||
func S2B(s string) (b []byte) {
|
||||
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
||||
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
bh.Data = sh.Data
|
||||
bh.Cap = sh.Len
|
||||
bh.Len = sh.Len
|
||||
return
|
||||
return unsafe.Slice(unsafe.StringData(s), len(s))
|
||||
}
|
||||
|
||||
const (
|
||||
|
Loading…
x
Reference in New Issue
Block a user