Moved function to generate sessions Ids from websocket to Utils
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user