open-vault/logical/uuid.go
2015-03-17 20:39:45 -05:00

22 lines
345 B
Go

package logical
import (
"crypto/rand"
"fmt"
"time"
)
// UUID returns a UUID.
func UUID() (string, error) {
unix := uint32(time.Now().UTC().Unix())
var b [12]byte
if _, err := rand.Read(b[:]); err != nil {
return "", err
}
return fmt.Sprintf("%08x-%04x-%04x-%04x-%04x%08x",
unix, b[0:2], b[2:4], b[4:6], b[6:8], b[8:]),
nil
}