1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 06:16:09 -04:00
v2fly/vid.go

39 lines
571 B
Go
Raw Normal View History

2015-09-05 11:48:38 -04:00
package core
import (
2015-09-06 16:10:42 -04:00
"encoding/hex"
"fmt"
2015-09-05 11:48:38 -04:00
)
type VID [16]byte
var byteGroups = []int{8, 4, 4, 4, 12}
// TODO: leverage a full functional UUID library
func UUIDToVID(uuid string) (v VID, err error) {
2015-09-06 16:10:42 -04:00
text := []byte(uuid)
if len(text) < 32 {
2015-09-05 11:48:38 -04:00
err = fmt.Errorf("uuid: invalid UUID string: %s", text)
return
}
b := v[:]
for _, byteGroup := range byteGroups {
if text[0] == '-' {
text = text[1:]
}
_, err = hex.Decode(b[:byteGroup/2], text[:byteGroup])
if err != nil {
return
}
text = text[byteGroup:]
b = b[byteGroup/2:]
}
return
}