Moved function to generate sessions Ids from websocket to Utils

This commit is contained in:
claudemiro
2015-01-16 13:18:24 -03:00
parent a51629f7b5
commit 1dc3105155
2 changed files with 14 additions and 14 deletions
+13
View File
@@ -6,7 +6,9 @@ package utils
import (
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
"encoding/base32"
"encoding/hex"
)
@@ -18,3 +20,14 @@ func HashMAC(message, key []byte) string {
return hex.EncodeToString(expected)
}
// Generate a new random Hash
func RandomHash() string {
b := make([]byte, 25)
if _, err := rand.Read(b); err != nil {
panic("websockets: Could not generate a random session ID")
}
return base32.StdEncoding.EncodeToString(b)
}