mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 02:57:40 +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
|
- name: Set up Go 1.x
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.19
|
go-version: 1.20
|
||||||
|
|
||||||
- name: Check out code into the Go module directory
|
- name: Check out code into the Go module directory
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
|||||||
module github.com/Mrs4s/MiraiGo
|
module github.com/Mrs4s/MiraiGo
|
||||||
|
|
||||||
go 1.19
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d
|
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package crypto
|
package crypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/ecdh"
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -51,3 +54,15 @@ func (e *ECDH) FetchPubKey(uin int64) {
|
|||||||
key, _ := hex.DecodeString(pubKey.Meta.PubKey)
|
key, _ := hex.DecodeString(pubKey.Meta.PubKey)
|
||||||
e.init(key) // todo check key sign
|
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 (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"reflect"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@ -50,10 +49,8 @@ func ConvertSubVersionToInt(str string) int32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// B2S converts byte slice to a string without memory allocation.
|
// 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 {
|
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.
|
// 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
|
// Note it may break if string and/or slice header will change
|
||||||
// in the future go versions.
|
// in the future go versions.
|
||||||
func S2B(s string) (b []byte) {
|
func S2B(s string) (b []byte) {
|
||||||
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
return unsafe.Slice(unsafe.StringData(s), len(s))
|
||||||
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
|
||||||
bh.Data = sh.Data
|
|
||||||
bh.Cap = sh.Len
|
|
||||||
bh.Len = sh.Len
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user