mirror of
https://github.com/nadoo/glider.git
synced 2026-11-19 07:09:42 +08:00
vless,vmess: support string to uuid mapping standard
This commit is contained in:
1 parent
926b364400
commit
aae2fc8256
5 files changed
+33
-10
No files matched your search
+11
-1
@@ -1,6 +1,7 @@
|
||||
package vless
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"net/url"
|
||||
@@ -62,8 +63,17 @@ func NewVLess(s string, d proxy.Dialer, p proxy.Proxy) (*VLess, error) {
|
||||
}
|
||||
|
||||
// StrToUUID converts string to uuid.
|
||||
// s fomat: "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
|
||||
func StrToUUID(s string) (uuid [16]byte, err error) {
|
||||
if len(s) >= 1 && len(s) <= 30 {
|
||||
h := sha1.New()
|
||||
h.Write(uuid[:])
|
||||
h.Write([]byte(s))
|
||||
u := h.Sum(nil)[:16]
|
||||
u[6] = (u[6] & 0x0f) | (5 << 4)
|
||||
u[8] = (u[8]&(0xff>>2) | (0x02 << 6))
|
||||
copy(uuid[:], u)
|
||||
return
|
||||
}
|
||||
b := []byte(strings.Replace(s, "-", "", -1))
|
||||
if len(b) != 32 {
|
||||
return uuid, errors.New("invalid UUID: " + s)
|
||||
|
||||
Reference in new issue
Block a user