tusd/src/http/uid.go

25 lines
567 B
Go
Raw Normal View History

2013-05-03 10:52:25 +00:00
package http
2013-03-17 15:42:47 +00:00
import (
"crypto/rand"
"fmt"
"io"
)
// uid returns a unique id. These ids consist of 128 bits from a
// cryptographically strong pseudo-random generator and are like uuids, but
// without the dashes and significant bits.
//
// See: http://en.wikipedia.org/wiki/UUID#Random_UUID_probability_of_duplicates
func uid() string {
id := make([]byte, 16)
_, err := io.ReadFull(rand.Reader, id)
if err != nil {
// This is probably an appropiate way to handle errors from our source
// for random bits.
panic(err)
}
return fmt.Sprintf("%x", id)
}