mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 13:16:07 +03:00
parent
157918859f
commit
822afb0cc8
@ -50,6 +50,8 @@ func (u *UUID) Equals(another *UUID) bool {
|
|||||||
func New() UUID {
|
func New() UUID {
|
||||||
var uuid UUID
|
var uuid UUID
|
||||||
common.Must2(rand.Read(uuid.Bytes()))
|
common.Must2(rand.Read(uuid.Bytes()))
|
||||||
|
uuid[6] = (uuid[6] & 0x0f) | (4 << 4)
|
||||||
|
uuid[8] = (uuid[8]&(0xff>>2) | (0x02 << 6))
|
||||||
return uuid
|
return uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,15 +8,33 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var cmdUUID = &base.Command{
|
var cmdUUID = &base.Command{
|
||||||
UsageLine: "{{.Exec}} uuid",
|
UsageLine: `{{.Exec}} uuid [-i "example"]`,
|
||||||
Short: "Generate new UUIDs",
|
Short: `Generate UUIDv4 or UUIDv5`,
|
||||||
Long: `
|
Long: `
|
||||||
Generate new UUIDs.
|
Generate UUIDv4 or UUIDv5.
|
||||||
`,
|
|
||||||
Run: executeUUID,
|
UUIDv4 (random): {{.Exec}} uuid
|
||||||
|
|
||||||
|
UUIDv5 (from input): {{.Exec}} uuid -i "example"
|
||||||
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeUUID(cmd *base.Command, args []string) {
|
func init() {
|
||||||
u := uuid.New()
|
cmdUUID.Run = executeUUID // break init loop
|
||||||
fmt.Println(u.String())
|
}
|
||||||
|
|
||||||
|
var input = cmdUUID.Flag.String("i", "", "")
|
||||||
|
|
||||||
|
func executeUUID(cmd *base.Command, args []string) {
|
||||||
|
var output string
|
||||||
|
if l := len(*input); l == 0 {
|
||||||
|
u := uuid.New()
|
||||||
|
output = u.String()
|
||||||
|
} else if l <= 30 {
|
||||||
|
u, _ := uuid.ParseString(*input)
|
||||||
|
output = u.String()
|
||||||
|
} else {
|
||||||
|
output = "Input must be within 30 bytes."
|
||||||
|
}
|
||||||
|
fmt.Println(output)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user