You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
395 B
18 lines
395 B
3 years ago
|
package crypto
|
||
|
|
||
|
import (
|
||
|
"encoding/binary"
|
||
|
"io"
|
||
|
)
|
||
|
|
||
|
// NewSessionID generates new random int64 from reader.
|
||
|
//
|
||
|
// Use crypto/rand.Reader if session id should be cryptographically safe.
|
||
|
func NewSessionID(reader io.Reader) (int64, error) {
|
||
|
bytes := make([]byte, 8)
|
||
|
if _, err := io.ReadFull(reader, bytes); err != nil {
|
||
|
return 0, err
|
||
|
}
|
||
|
return int64(binary.LittleEndian.Uint64(bytes)), nil
|
||
|
}
|