mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-12-23 22:19:49 +00:00
Support for VLESS & VMess UUID v5 mapping standard
https://github.com/XTLS/Xray-core/issues/158
This commit is contained in:
parent
96adf3fbca
commit
40271c09a0
@ -3,6 +3,7 @@ package uuid // import "github.com/xtls/xray-core/common/uuid"
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
@ -67,8 +68,18 @@ func ParseString(str string) (UUID, error) {
|
||||
var uuid UUID
|
||||
|
||||
text := []byte(str)
|
||||
if len(text) < 32 {
|
||||
return uuid, errors.New("invalid UUID: ", str)
|
||||
if l := len(text); l < 32 || l > 36 {
|
||||
if l == 0 || l > 30 {
|
||||
return uuid, errors.New("invalid UUID: ", str)
|
||||
}
|
||||
h := sha1.New()
|
||||
h.Write(uuid[:])
|
||||
h.Write(text)
|
||||
u := h.Sum(nil)[:16]
|
||||
u[6] = (u[6] & 0x0f) | (5 << 4)
|
||||
u[8] = (u[8]&(0xff>>2) | (0x02 << 6))
|
||||
copy(uuid[:], u)
|
||||
return uuid, nil
|
||||
}
|
||||
|
||||
b := uuid.Bytes()
|
||||
|
@ -35,9 +35,10 @@ func TestParseString(t *testing.T) {
|
||||
t.Fatal(r)
|
||||
}
|
||||
|
||||
_, err = ParseString("2418d087")
|
||||
if err == nil {
|
||||
t.Fatal("Expect error but nil")
|
||||
u0, _ := ParseString("example")
|
||||
u5, _ := ParseString("feb54431-301b-52bb-a6dd-e1e93e81bb9e")
|
||||
if r := cmp.Diff(u0, u5); r != "" {
|
||||
t.Fatal(r)
|
||||
}
|
||||
|
||||
_, err = ParseString("2418d087-648k-4990-86e8-19dca1d006d3")
|
||||
|
Loading…
Reference in New Issue
Block a user